using System;
using System.IO;
using System.Collections.Generic;
using System.Xml;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Intermediate;

using GameComponents;
using Natur.MapManager;

namespace Natur
{
    using XnaButtonState = Microsoft.Xna.Framework.Input.ButtonState;
    using Rectangle = Microsoft.Xna.Framework.Rectangle;
    using Color = Microsoft.Xna.Framework.Color;

    public class Run : Microsoft.Xna.Framework.Game
    {
        enum GameState { Normal = 0, Simulating }
        enum MenuState { Normal = 0, Create_Structure, Load, Message, Save, TriggerCreate }
        enum BaseType { Cone = 0, Cube, Cylinder, FuturePillar, Generator, GrateWindow, Plane, PowerPlant1, Sphere, Triangle, Wall }
        enum SnapSide { Top = 0, Bottom, Left, Right }

        const float PLANE_NEAR = 1;
        const float PLANE_FAR = 1000;
        const float GRID_MINOR = .001f;
        const float GRID_MAJOR = .25f;

        const int MAP_SET_COUNT = 1;

        const float JOYSTICK_SPEED = 20;
        const float CAMERA_RADIUS = 1.5f;
        const float DEFAULT_ROT_SPEED = 0.196349375f;
        
        const float DEFAULT_DIMENSION = 1.75f;
        const float DEFAULT_INTENSITY = 1;
        const int PALETTE_COUNT = 2;

        #region ASSETS
        // Sounds
        const int SND_CLICK = 0;
        const int SND_DING = 1;
        const int SND_COUNT = 2;

        // Fonts
        const int FONTS_TINY = 0;
        const int FONTS_SMALL = 1;
        const int FONTS_MEDIUM = 2;
        const int FONTS_LARGE = 3;
        const int FONTS_COUNT = 4;

        // Models
        const int MODEL_SPHERE = 0;
        const int MODEL_CONE = 1;
        const int MODEL_CUBE = 2;
        const int MODEL_CYLINDER = 3;
        const int MODEL_PLANE = 4;
        const int MODEL_POWERPLANT_1 = 5;
        const int MODEL_FUTURE_PILLAR = 6;
        const int MODEL_GENERATOR = 7;
        const int MODEL_GRATE_WINDOW = 8;
        const int MODEL_TRIANGLE = 9;
        const int MODEL_COUNT = 10;

        // Menu Textures
        const int MENU_DARK_PURPLE = 0;
        const int MENU_DARK_GRAY = 1;
        const int MENU_LIGHT_GRAY = 2;
        const int MENU_MEDIUM_BLUE = 3;
        const int MENU_BLUE_GRAY = 4;

        const int MENU_ANIMATION = 5;
        const int MENU_ANIMATION_FRAME = 6;
        const int MENU_ANIMATION_STRUCTURE = 7;

        const int MENU_ADD_LOCATION = 24;
        const int MENU_ADD_SPAWN = 50;
        const int MENU_ADD_RELAY = 52;

        const int MENU_PAINT = 34;
        const int MENU_PIN = 33;
        const int MENU_UNPIN = 40;
        const int MENU_VERTEX_SNAP = 20;
        const int MENU_LINK_RELAY = 53;

        const int MENU_BOUND_BOX = 35;
        const int MENU_BOUND_SPHERE = 36;
        const int MENU_ADD_BOUND = 43;

        const int MENU_ADD_STRUCTURE = 8;
        const int MENU_ADD_INTERACTIVE = 46;
        const int MENU_BASE_BOX = 37;
        const int MENU_BASE_CONE = 45;
        const int MENU_BASE_CYLINDER = 12;
        const int MENU_BASE_SPHERE = 38;
        const int MENU_BASE_WALL = 11;

        const int MENU_ADD_LIGHT = 9;
        const int MENU_ADD_DIRECT_LIGHT = 41;
        const int MENU_BAKE_LIGHT = 10;

        const int MENU_SCALE = 13;
        const int MENU_ARROW_UP = 14;
        const int MENU_ARROW_DOWN = 15;
        const int MENU_ARROW_LEFT = 16;
        const int MENU_ARROW_RIGHT = 17;
        const int MENU_MINUS = 18;
        const int MENU_PLUS = 19;

        const int MENU_CONTINUOUS = 21;
        const int MENU_COMMAND = 22;
        const int MENU_PROXIMITY = 23;

        const int MENU_LAYER_CONSTRUCTION = 25;
        const int MENU_LAYER_LOCATION = 26;
        const int MENU_LAYER_BOUND = 32;
        const int MENU_LAYER_LIGHT = 42;
        const int MENU_EYE = 27;

        const int MENU_WND_ARROW_RIGHT = 28;
        const int MENU_WND_ARROW_DOWN = 29;
        const int MENU_DELETE = 31;

        const int MENU_GUIDE = 51;
        const int MENU_QUICK_GUIDE = 39;
        const int MENU_PALETTE_1 = 30;
        const int MENU_PALETTE_2 = 44;

        const int MENU_PLAY = 47;
        const int MENU_PAUSE = 48;
        const int MENU_STOP = 49;

        const int MENU_ABOUT = 55;
        const int MENU_COUNT = 56;

        // Menu Render Targets
        const int RENDER_ACTIVE_TEX = 0;
        const int RENDER_CREATE_STRUCTURE = 1;
        const int RENDER_COUNT = 2;

        // Effects
        const int EFFECT_BASIC = 0;
        const int EFFECT_TEX_HIGHLIGHT = 1;
        const int EFFECT_SECTOR_BASIC = 2;
        const int EFFECT_COUNT = 3;
        #endregion

        StorageDevice storageDevice;
        Object storageState;

        public delegate void MessageConfirm();
        MessageConfirm callbackConfirm;

        #region STANDARD VARIABLES
        GraphicsDeviceManager graphicsManager;
        ContentManager mainMenuManager;
        SpriteBatch spriteBatch;
        Rectangle safeArea;

        DepthStencilState stateNoDepth;

        // Global
        SoundEffect[] arySounds = new SoundEffect[SND_COUNT];
        SpriteFont[] aryFonts = new SpriteFont[FONTS_COUNT];
        Model[] aryModels = new Model[MODEL_COUNT];
        Effect[] aryEffects = new Effect[EFFECT_COUNT];
        CustomVD[] aryCustomVerts;
        Int16[] aryCustomInds;

        // Main Menu
        HUD hudMapManager;
        HUD hudView;
        HUD hudConstruction;
        HUD hudTexture;
        HUD hudTransform;
        HUD hudAnimation;
        HUD hudCreateStructure;
        HUD hudTrigger;
        
        Texture2D[] aryTextures = new Texture2D[MENU_COUNT];
        RenderTarget2D[] aryRenderTargets = new RenderTarget2D[RENDER_COUNT];

        // Map
        Map mainMap;

        // Input
        KeyboardState baseKey;
        MouseState baseMouse;

        // Camera
        Player camera;
        Player previewCamera;
        Matrix viewMat = Matrix.Identity;
        Matrix projMat = Matrix.Identity;
        Matrix worldMat = Matrix.Identity;
        #endregion

        #region CONTROL AND CONSTRUCTION
        // Control
        GameState gameState = GameState.Normal;
        MenuState menuState = MenuState.Normal;

        string currentFile = null;
        LayerType currentLayer = LayerType.Construction;
        bool showConstruction = true;
        bool showBounds = true;
        bool showLocations = true;
        bool showLights = true;
        string currentButtonName = null;

        int currentSector = 0;
        List<MapEntity> lstSelected = new List<MapEntity>(5);

        // Construction
        bool autoState = true;
        bool vSnap = true;
        string structTriggerType = "Command";

        bool structInteractive = false;
        BoundType structBound = BoundType.Box;
        BaseType structBase = BaseType.Wall;
        bool affectX = true, affectY = true, affectZ = true;
        float structProtrusion = 50;
        float structRoughness = 50;

        Vector3 structPosition = Vector3.Zero;
        Vector3 structForward = Vector3.Forward;
        Vector3 structUp = Vector3.Up;

        float structW = DEFAULT_DIMENSION;
        float structH = DEFAULT_DIMENSION;
        float structD = DEFAULT_DIMENSION;

        int structPalette = 0;
        Vector2 structTexStart = Vector2.Zero;
        Vector2 structTexDimension = new Vector2(.125f, .125f);

        float shiftSpeed = .25f;
        float scaleSpeed = .25f;
        float rotateSpeed = DEFAULT_ROT_SPEED;
        #endregion

        public Run()
        {
            graphicsManager = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            // Make Fullscreen
            graphicsManager.PreferredBackBufferWidth = 1280;
            graphicsManager.PreferredBackBufferHeight = 720;
            //this.graphicsManager.IsFullScreen = true;
            graphicsManager.SynchronizeWithVerticalRetrace = true;
            // Enable Cursor
            this.IsMouseVisible = true;
        }

        // ******* USER METHODS *******

        private void AddSelected(params MapEntity[] newSelected)
        {
            bool updateAnimation = false;
            bool updateTrigger = false;
            for (int pS = 0; pS < newSelected.Length; pS++)
            {
                if ((!lstSelected.Contains(newSelected[pS])) && (newSelected[pS].Type != ObjectType.Empty))
                {
                    lstSelected.Add(newSelected[pS]);
                    switch (newSelected[pS].Type)
                    {
                        case ObjectType.Animation:
                        case ObjectType.Frame:
                            updateAnimation = true;
                            break;
                        case ObjectType.Trigger:
                            updateTrigger = true;
                            break;
                    }
                }
            }
            if (updateAnimation) { UpdateAnimationView(); }
            if (updateTrigger) { UpdateTriggerView(); }
            UpdateObjectProperties();
        }

        private void ClearCustomVertices()
        {
            bool snapW = false, snapH = false, snapD = false;
            float currentProtrusion = 0;
            Matrix scaleMat = Matrix.Identity;
            Matrix newWorld = Matrix.Identity;
            int modelIndex = 0;

            switch (structBase)
            {
                case BaseType.Cone:
                    snapH = true;
                    modelIndex = MODEL_CONE;
                    break;
                case BaseType.Cube:
                    snapW = true; snapH = true; snapD = true;
                    modelIndex = MODEL_CUBE;
                    break;;
                case BaseType.Cylinder:
                    snapH = true;
                    modelIndex = MODEL_CYLINDER;
                    break;
                case BaseType.FuturePillar:
                    modelIndex = MODEL_FUTURE_PILLAR;
                    break;
                case BaseType.Generator:
                    modelIndex = MODEL_GENERATOR;
                    break;
                case BaseType.GrateWindow:
                    modelIndex = MODEL_GRATE_WINDOW;
                    break;
                case BaseType.Plane:
                    snapW = true; snapH = true; snapD = true;
                    modelIndex = MODEL_PLANE;
                    break;
                case BaseType.PowerPlant1:
                    modelIndex = MODEL_POWERPLANT_1;
                    break;
                case BaseType.Sphere:
                    modelIndex = MODEL_SPHERE;
                    break;
                case BaseType.Triangle:
                    snapW = true; snapH = true; snapD = true;
                    modelIndex = MODEL_TRIANGLE;
                    break;
                case BaseType.Wall:
                    snapW = true; snapH = true; snapD = true;
                    modelIndex = MODEL_CUBE;
                    break;
            }
            scaleMat = Matrix.CreateScale(structW, structH, structD);
            newWorld = Matrix.CreateWorld(structPosition, structForward, structUp);

            // Copy in and convert vertices - resize to default
            VertexPositionNormalTexture[] aryVerts = new VertexPositionNormalTexture[aryModels[modelIndex].Meshes[0].MeshParts[0].VertexBuffer.VertexCount];
            aryCustomVerts = new CustomVD[aryVerts.Length];
            aryModels[modelIndex].Meshes[0].MeshParts[0].VertexBuffer.GetData<VertexPositionNormalTexture>(aryVerts);
            for (int i = 0; i < aryVerts.Length; i++)
            {
                CustomVD newVert = new CustomVD(aryVerts[i].Position, aryVerts[i].Normal, aryVerts[i].TextureCoordinate, Color.Gray);
                Vector3 snappedVertex = newVert.Position;
                Vector3 editVertex = snappedVertex;
                Vector2 newTexCoord = newVert.TexCoord;
                float newProtrusion = 2 * GRID_MINOR * ((structProtrusion - 50) / (float)Math.Sqrt(Vector3.Distance(snappedVertex, Vector3.Zero)));

                if (editVertex != Vector3.Zero)
                {
                    // Scale
                    snappedVertex = Vector3.Transform(snappedVertex, scaleMat);
                    // Vertex snapping
                    if (snapW) { snappedVertex.X = (float)Math.Floor(.5f + (snappedVertex.X / GRID_MINOR)) * GRID_MINOR; }
                    else { snappedVertex.X = (float)Math.Floor(.5f + (snappedVertex.X / GRID_MINOR)) * GRID_MINOR; }
                    if (snapH) { snappedVertex.Y = (float)Math.Floor(.5f + (snappedVertex.Y / GRID_MINOR)) * GRID_MINOR; }
                    else { snappedVertex.Y = (float)Math.Floor(.5f + (snappedVertex.Y / GRID_MINOR)) * GRID_MINOR; }
                    if (snapD) { snappedVertex.Z = (float)Math.Floor(.5f + (snappedVertex.Z / GRID_MINOR)) * GRID_MINOR; }
                    else { snappedVertex.Z = (float)Math.Floor(.5f + (snappedVertex.Z / GRID_MINOR)) * GRID_MINOR; }

                    // Protrusion
                    if (newProtrusion > currentProtrusion) { currentProtrusion = newProtrusion; }
                    editVertex = snappedVertex;
                    editVertex += newProtrusion * newVert.Normal;
                }
                // Resize texture coordinates
                newTexCoord.X = structTexStart.X + (newTexCoord.X * structTexDimension.X);
                newTexCoord.Y = structTexStart.Y + (newTexCoord.Y * structTexDimension.Y);

                // Finish and add
                newVert.TexCoord = newTexCoord;
                newVert.Position = Vector3.Transform(editVertex, newWorld);
                newVert.Normal = Vector3.TransformNormal(newVert.Normal, newWorld);
                aryCustomVerts[i] = newVert;
            }

            if (affectX) { structW += currentProtrusion; }
            if (affectY) { structH += currentProtrusion; }
            if (affectZ) { structD += currentProtrusion; }

            // Copy in indices
            aryCustomInds = new Int16[aryModels[modelIndex].Meshes[0].MeshParts[0].IndexBuffer.IndexCount];
            aryModels[modelIndex].Meshes[0].MeshParts[0].IndexBuffer.GetData<Int16>(aryCustomInds);
        }

        private void ClearSelected(params ObjectType[] aryPreserve)
        {
            bool updateAnimation = false;
            bool updateTrigger = false;
            for (int i = 0; i < lstSelected.Count; i++)
            {
                bool preserve = false;
                for (int a = 0; a < aryPreserve.Length; a++)
                { if (aryPreserve[a] == lstSelected[i].Type) { preserve = true; break; } }
                if (!preserve)
                {
                    switch (lstSelected[i].Type)
                    {
                        case ObjectType.Animation:
                        case ObjectType.Frame:
                            updateAnimation = true;
                            break;
                        case ObjectType.Trigger:
                            updateTrigger = true;
                            break;
                    }
                    lstSelected.RemoveAt(i);
                    i--;
                }
            }
            if (updateAnimation) { UpdateAnimationView(); }
            if (updateTrigger) { UpdateTriggerView(); }
            UpdateObjectProperties();
        }

        private void ClearStructs(bool clearAll)
        {
            if (clearAll)
            {
                structProtrusion = 50;
                hudCreateStructure["Protrusion"].ModifyField("Amount", structProtrusion.ToString());
                hudCreateStructure["Protrusion"].ModifyField("Ticker", new Vector2(
                    hudCreateStructure["Protrusion"]["Line"].DrawRect.X
                    + (structProtrusion / 100) * hudCreateStructure["Protrusion"]["Line"].DrawRect.Width,
                    hudCreateStructure["Protrusion"]["Ticker"].DrawRect.Y));
                structRoughness = 50;
                hudCreateStructure["Roughness"].ModifyField("Amount", structRoughness.ToString());
                hudCreateStructure["Roughness"].ModifyField("Ticker", new Vector2(
                    hudCreateStructure["Roughness"]["Line"].DrawRect.X
                    + (structRoughness / 100) * hudCreateStructure["Roughness"]["Line"].DrawRect.Width,
                    hudCreateStructure["Roughness"]["Ticker"].DrawRect.Y));
            }

            // if build from active
            if (lstSelected.Count > 0)
            {
                DimensionedStructure structHold;
                // Copy from pinned if possible
                MapEntity selectedPin = IsSelected(ObjectType.Pinned);
                if (selectedPin != null)
                { structHold = Map.GetDimensionedStructure(selectedPin); }
                else
                {
                    // Copy from structure if possible
                    MapEntity selectedStruct = IsSelected(ObjectType.Structure);
                    if (selectedStruct != null)
                    { structHold = Map.GetDimensionedStructure(selectedStruct); }
                    // else first selected
                    else { structHold = Map.GetDimensionedStructure(lstSelected[0]); }
                }
                structW = structHold.WRadius;
                structH = structHold.HRadius;
                structD = structHold.DRadius;
                structPosition = structHold.Position;
                structForward = structHold.Forward;
                structUp = structHold.Up;
            }
            else
            {
                structPosition = camera.Position + camera.Forward * 2.5f * CAMERA_RADIUS;
                structForward = Vector3.Forward;
                structUp = Vector3.Up;
                
                switch (structBase)
                {
                    case BaseType.Cone:
                        structW = DEFAULT_DIMENSION;
                        structH = DEFAULT_DIMENSION;
                        structD = DEFAULT_DIMENSION;
                        break;
                    case BaseType.Cube:
                        structW = DEFAULT_DIMENSION;
                        structH = DEFAULT_DIMENSION;
                        structD = DEFAULT_DIMENSION;
                        break;
                    case BaseType.Cylinder:
                        structW = DEFAULT_DIMENSION;
                        structH = 2 * DEFAULT_DIMENSION;
                        structD = DEFAULT_DIMENSION;
                        break;
                    case BaseType.Plane:
                        structW = 2 * DEFAULT_DIMENSION;
                        structH = 2 * DEFAULT_DIMENSION;
                        structD = 1;
                        break;
                    case BaseType.Sphere:
                        structW = DEFAULT_DIMENSION;
                        structH = DEFAULT_DIMENSION;
                        structD = DEFAULT_DIMENSION;
                        break;
                    case BaseType.Wall:
                        structW = 2 * DEFAULT_DIMENSION;
                        structH = 2 * DEFAULT_DIMENSION;
                        structD = .18f;
                        break;
                }
            }
        }

        protected override void Draw(GameTime gameTime)
        {
            // Save old states
            DepthStencilState oldDepth = GraphicsDevice.DepthStencilState;

            GraphicsDevice.Clear(new Color(20, 20, 20, 255));

            //BasicEffect playerEffect = new BasicEffect(GraphicsDevice);
            //playerEffect.View = viewMat;
            //playerEffect.Projection = projMat;

            switch (gameState)
            {
                case GameState.Simulating:
                    // Draw Map
                    mainMap.Draw(GraphicsDevice, viewMat, projMat, camera.Forward, showBounds, showConstruction, showLights, showLocations);

                    // Draw Player
                    /*for (int i = 0; i < Player.BOUND_COUNT; i++)
                    {
                        //if (i != Player.BOUND_AREA)
                        //{
                            playerEffect.World = Matrix.CreateScale(camera.Bounds[i].Radius) * Matrix.CreateTranslation(camera.Bounds[i].Center);
                            aryModels[MODEL_SPHERE].Meshes[0].MeshParts[0].Effect = playerEffect;
                            aryModels[MODEL_SPHERE].Meshes[0].Draw();
                       // }
                    }*/

                    // Draw Menu
                    GraphicsDevice.DepthStencilState = stateNoDepth;
                    break;
                case GameState.Normal:
                    // Redraw menu graphics
                    UpdateMenuGraphics();
                    GraphicsDevice.Clear(new Color(20, 20, 20, 255));

                    // Draw Map
                    mainMap.Draw(GraphicsDevice, viewMat, projMat, camera.Forward, showBounds, showConstruction, showLights, showLocations);

                    // Draw Player
                    /*for (int i = 0; i < Player.BOUND_COUNT; i++)
                    {
                        if (i != Player.BOUND_AREA)
                        {
                            playerEffect.World = Matrix.CreateScale(camera.Bounds[i].Radius) * Matrix.CreateTranslation(camera.Bounds[i].Center);
                            aryModels[MODEL_SPHERE].Meshes[0].MeshParts[0].Effect = playerEffect;
                            aryModels[MODEL_SPHERE].Meshes[0].Draw();
                        }
                    }*/

                    // Draw Main Menu
                    GraphicsDevice.DepthStencilState = stateNoDepth;

                    hudView.Draw();
                    hudConstruction.Draw();
                    hudTexture.Draw();
                    hudTransform.Draw();
                    hudAnimation.Draw();
                    hudTrigger.Draw();
                    hudMapManager.Draw();
                    switch (menuState)
                    {
                        case MenuState.Normal:
                            break;
                        case MenuState.Create_Structure:
                            hudCreateStructure.Draw();
                            break;
                        case MenuState.TriggerCreate:
                            break;
                    }
                    break;
            }
            // Restore old states
            GraphicsDevice.DepthStencilState = oldDepth;
            base.Draw(gameTime);
        }

        private void ExitNatur()
        { this.Exit(); }

        private void ExportMap()
        {
            if (storageDevice.IsConnected)
            {
                string fileName = "Exported_";
                int nameIndex = 0;
                IAsyncResult syncResult = storageDevice.BeginOpenContainer("Exports", null, null);

                // Wait for sync
                syncResult.AsyncWaitHandle.WaitOne();
                StorageContainer storageContainer = storageDevice.EndOpenContainer(syncResult);

                while (storageContainer.FileExists(fileName + nameIndex.ToString() + ".xml"))
                { nameIndex++; }

                // Save map
                MapData newSaveData = mainMap.ExportMap();
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Indent = true;

                // Create file and save
                Stream fileStream = storageContainer.CreateFile(fileName + nameIndex.ToString() + ".xml");
                using (XmlWriter writer = XmlWriter.Create(fileStream, settings))
                { IntermediateSerializer.Serialize(writer, newSaveData, null); }

                // Close
                fileStream.Close();
                storageContainer.Dispose();
                // Complete
                arySounds[SND_DING].Play();
            }
        }

        private int GetPaletteIndex(int localValue)
        {
            int foundIndex = -1;
            switch (localValue)
            {
                case 0:
                    foundIndex = MENU_PALETTE_1;
                    break;
                case 1:
                    foundIndex = MENU_PALETTE_2;
                    break;
            }
            return foundIndex;
        }

        public void GetStorageDevice(IAsyncResult syncResult)
        { storageDevice = StorageDevice.EndShowSelector(syncResult); }

        protected override void Initialize()
        {
            safeArea = GraphicsDevice.Viewport.TitleSafeArea;
            stateNoDepth = new DepthStencilState();
            stateNoDepth.DepthBufferEnable = false;

            camera = new Player("AFallenApple", 0, 2 * CAMERA_RADIUS * Vector3.Backward, Vector3.Forward, Vector3.Up, 4,
                MoveType.Float, 50, 75, 1, 20, 30, 5, 6);
            camera.SetBound(Player.BOUND_FEET, new BoundingSphere(Vector3.Zero, 2 * CAMERA_RADIUS / 6));
            camera.SetBound(Player.BOUND_BODY, new BoundingSphere(Vector3.Zero, 2 * CAMERA_RADIUS / 6));
            camera.SetBound(Player.BOUND_HEAD, new BoundingSphere(Vector3.Zero, 2 * CAMERA_RADIUS / 6));
            camera.UpdateDimensions();

            previewCamera = new Player("AFallenApple", 0, 2 * CAMERA_RADIUS * Vector3.Backward, Vector3.Forward, Vector3.Up, 4,
                MoveType.Float, 20, 30, 1, 30, 50, 5, 6);
            viewMat = camera.LookAt;
            projMat = Matrix.CreatePerspectiveFieldOfView((float)(Math.PI / 3), GraphicsDevice.Viewport.AspectRatio, PLANE_NEAR, PLANE_FAR);
            base.Initialize();
        }

        private MapEntity IsSelected(ObjectType searchType)
        {
            MapEntity isFound = null;
            for (int i = 0; i < lstSelected.Count; i++)
            {
                if (lstSelected[i].Type == searchType)
                { isFound = lstSelected[i]; break; }
            }
            return isFound;
        }

        private bool IsSelected(MapEntity searchEntity)
        {
            bool isSelected = false;
            for (int i = 0; i < lstSelected.Count; i++)
            { if (lstSelected[i] == searchEntity) { isSelected = true; break; } }
            return isSelected;
        }

        protected override void LoadContent()
        {
            // For storage
            StorageDevice.BeginShowSelector(GetStorageDevice, storageState);

            mainMenuManager = new ContentManager(Content.ServiceProvider, "Content");
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // *** Global Assets

            // Sounds
            arySounds[SND_CLICK] = Content.Load<SoundEffect>("Sounds\\Click");
            arySounds[SND_DING] = Content.Load<SoundEffect>("Sounds\\Ding");

            // Fonts
            aryFonts[FONTS_TINY] = Content.Load<SpriteFont>("Fonts\\Tiny");
            aryFonts[FONTS_SMALL] = Content.Load<SpriteFont>("Fonts\\Small");
            aryFonts[FONTS_MEDIUM] = Content.Load<SpriteFont>("Fonts\\Medium");
            aryFonts[FONTS_LARGE] = Content.Load<SpriteFont>("Fonts\\Large");

            // Load Models
            aryModels[MODEL_SPHERE] = Content.Load<Model>("Models\\Sphere");
            aryModels[MODEL_CONE] = Content.Load<Model>("Models\\Cone");
            aryModels[MODEL_CUBE] = Content.Load<Model>("Models\\Cube");
            aryModels[MODEL_CYLINDER] = Content.Load<Model>("Models\\Cylinder");
            aryModels[MODEL_FUTURE_PILLAR] = Content.Load<Model>("Models\\FuturePillar");
            aryModels[MODEL_GENERATOR] = Content.Load<Model>("Models\\Generator");
            aryModels[MODEL_GRATE_WINDOW] = Content.Load<Model>("Models\\GrateWindow");
            aryModels[MODEL_PLANE] = Content.Load<Model>("Models\\Plane");
            aryModels[MODEL_TRIANGLE] = Content.Load<Model>("Models\\Triangle");

            // Extended Models
            aryModels[MODEL_POWERPLANT_1] = Content.Load<Model>("Models\\PowerPlant_1");

            // Effects
            aryEffects[EFFECT_BASIC] = Content.Load<Effect>("Effects\\hudBasic");
            
            aryEffects[EFFECT_TEX_HIGHLIGHT] = Content.Load<Effect>("Effects\\hudTexHighligh");
            aryEffects[EFFECT_TEX_HIGHLIGHT].CurrentTechnique = aryEffects[EFFECT_TEX_HIGHLIGHT].Techniques["Basic"];
            aryEffects[EFFECT_TEX_HIGHLIGHT].Parameters["texStart"].SetValue(structTexStart);
            aryEffects[EFFECT_TEX_HIGHLIGHT].Parameters["texDimension"].SetValue(structTexDimension);

            // Map Effects
            aryEffects[EFFECT_SECTOR_BASIC] = mainMenuManager.Load<Effect>("Effects\\SectorBasic");
            aryEffects[EFFECT_SECTOR_BASIC].CurrentTechnique = aryEffects[EFFECT_SECTOR_BASIC].Techniques["Basic"];

            // Create Main Menu
            LoadMainMenu();

            // Set for default palette
            aryEffects[EFFECT_SECTOR_BASIC].Parameters["baseTexture"].SetValue(aryTextures[MENU_PALETTE_1]);

            // Create Map
            mainMap = new Map(graphicsManager.GraphicsDevice, Content.ServiceProvider, GRID_MAJOR);
            currentSector = mainMap.AddSector(0, aryEffects[EFFECT_SECTOR_BASIC].Clone());

            // Input
            baseKey = Keyboard.GetState();
            baseMouse = Mouse.GetState();
        }

        private void LoadMainMenu()
        {
            #region LOAD TEXTURES and RENDER TARGETS
            aryTextures[MENU_DARK_PURPLE] = mainMenuManager.Load<Texture2D>("Textures\\MenuDarkPurple");
            aryTextures[MENU_DARK_GRAY] = mainMenuManager.Load<Texture2D>("Textures\\MenuDarkGray");
            aryTextures[MENU_LIGHT_GRAY] = mainMenuManager.Load<Texture2D>("Textures\\MenuLightGray");
            aryTextures[MENU_MEDIUM_BLUE] = mainMenuManager.Load<Texture2D>("Textures\\MenuMediumBlue");
            aryTextures[MENU_BLUE_GRAY] = mainMenuManager.Load<Texture2D>("Textures\\MenuBlueGray");
            
            aryTextures[MENU_ANIMATION] = mainMenuManager.Load<Texture2D>("Textures\\MenuAnimation");
            aryTextures[MENU_ANIMATION_FRAME] = mainMenuManager.Load<Texture2D>("Textures\\MenuAnimationFrame");
            aryTextures[MENU_ANIMATION_STRUCTURE] = mainMenuManager.Load<Texture2D>("Textures\\MenuAnimationStructure");

            aryTextures[MENU_ADD_LOCATION] = mainMenuManager.Load<Texture2D>("Textures\\MenuAddLocation");
            aryTextures[MENU_ADD_SPAWN] = mainMenuManager.Load<Texture2D>("Textures\\MenuAddSpawn");
            aryTextures[MENU_ADD_RELAY] = mainMenuManager.Load<Texture2D>("Textures\\MenuAddRelay");

            aryTextures[MENU_PAINT] = mainMenuManager.Load<Texture2D>("Textures\\MenuPaint");
            aryTextures[MENU_PIN] = mainMenuManager.Load<Texture2D>("Textures\\MenuPin");
            aryTextures[MENU_UNPIN] = mainMenuManager.Load<Texture2D>("Textures\\MenuUnpin");
            aryTextures[MENU_VERTEX_SNAP] = mainMenuManager.Load<Texture2D>("Textures\\MenuVertexSnap");
            aryTextures[MENU_LINK_RELAY] = mainMenuManager.Load<Texture2D>("Textures\\MenuLinkRelay");
            
            aryTextures[MENU_BOUND_BOX] = mainMenuManager.Load<Texture2D>("Textures\\MenuBoundBox");
            aryTextures[MENU_BOUND_SPHERE] = mainMenuManager.Load<Texture2D>("Textures\\MenuBoundSphere");
            aryTextures[MENU_ADD_BOUND] = mainMenuManager.Load<Texture2D>("Textures\\MenuAddBound");
            
            aryTextures[MENU_ADD_STRUCTURE] = mainMenuManager.Load<Texture2D>("Textures\\MenuAddStructure");
            aryTextures[MENU_ADD_INTERACTIVE] = mainMenuManager.Load<Texture2D>("Textures\\MenuAddInteractive");
            aryTextures[MENU_BASE_WALL] = mainMenuManager.Load<Texture2D>("Textures\\MenuAddWall");
            aryTextures[MENU_BASE_CONE] = mainMenuManager.Load<Texture2D>("Textures\\MenuAddCone");
            aryTextures[MENU_BASE_CYLINDER] = mainMenuManager.Load<Texture2D>("Textures\\MenuAddCylinder");
            aryTextures[MENU_BASE_BOX] = mainMenuManager.Load<Texture2D>("Textures\\MenuAddBox");
            aryTextures[MENU_BASE_SPHERE] = mainMenuManager.Load<Texture2D>("Textures\\MenuAddSphere");
            
            aryTextures[MENU_ADD_LIGHT] = mainMenuManager.Load<Texture2D>("Textures\\MenuAddLight");
            aryTextures[MENU_ADD_DIRECT_LIGHT] = mainMenuManager.Load<Texture2D>("Textures\\MenuAddDirectLight");
            aryTextures[MENU_BAKE_LIGHT] = mainMenuManager.Load<Texture2D>("Textures\\MenuBakeLight");

            aryTextures[MENU_SCALE] = mainMenuManager.Load<Texture2D>("Textures\\MenuScale");
            aryTextures[MENU_ARROW_UP] = mainMenuManager.Load<Texture2D>("Textures\\MenuArrowUp");
            aryTextures[MENU_ARROW_DOWN] = mainMenuManager.Load<Texture2D>("Textures\\MenuArrowDown");
            aryTextures[MENU_ARROW_LEFT] = mainMenuManager.Load<Texture2D>("Textures\\MenuArrowLeft");
            aryTextures[MENU_ARROW_RIGHT] = mainMenuManager.Load<Texture2D>("Textures\\MenuArrowRight");
            aryTextures[MENU_MINUS] = mainMenuManager.Load<Texture2D>("Textures\\MenuMinus");
            aryTextures[MENU_PLUS] = mainMenuManager.Load<Texture2D>("Textures\\MenuPlus");

            aryTextures[MENU_COMMAND] = mainMenuManager.Load<Texture2D>("Textures\\MenuCommand");
            aryTextures[MENU_CONTINUOUS] = mainMenuManager.Load<Texture2D>("Textures\\MenuContinuous");
            aryTextures[MENU_PROXIMITY] = mainMenuManager.Load<Texture2D>("Textures\\MenuProximity");

            aryTextures[MENU_LAYER_CONSTRUCTION] = mainMenuManager.Load<Texture2D>("Textures\\MenuLayerConstruction");
            aryTextures[MENU_LAYER_LIGHT] = mainMenuManager.Load<Texture2D>("Textures\\MenuLayerLight");
            aryTextures[MENU_LAYER_LOCATION] = mainMenuManager.Load<Texture2D>("Textures\\MenuLayerLocation");
            aryTextures[MENU_LAYER_BOUND] = mainMenuManager.Load<Texture2D>("Textures\\MenuLayerBound");
            aryTextures[MENU_EYE] = mainMenuManager.Load<Texture2D>("Textures\\MenuEye");

            aryTextures[MENU_WND_ARROW_RIGHT] = mainMenuManager.Load<Texture2D>("Textures\\MenuWndArrowRight");
            aryTextures[MENU_WND_ARROW_DOWN] = mainMenuManager.Load<Texture2D>("Textures\\MenuWndArrowDown");
            aryTextures[MENU_DELETE] = mainMenuManager.Load<Texture2D>("Textures\\MenuDelete");

            aryTextures[MENU_ABOUT] = mainMenuManager.Load<Texture2D>("Textures\\MenuAbout");
            aryTextures[MENU_GUIDE] = mainMenuManager.Load<Texture2D>("Textures\\MenuGuide");
            aryTextures[MENU_QUICK_GUIDE] = mainMenuManager.Load<Texture2D>("Textures\\MenuQuickGuide");
            aryTextures[MENU_PALETTE_1] = mainMenuManager.Load<Texture2D>("Textures\\MenuPalette1");
            aryTextures[MENU_PALETTE_2] = mainMenuManager.Load<Texture2D>("Textures\\MapPalette2");

            aryTextures[MENU_PLAY] = mainMenuManager.Load<Texture2D>("Textures\\MenuPlay");
            aryTextures[MENU_PAUSE] = mainMenuManager.Load<Texture2D>("Textures\\MenuPause");
            aryTextures[MENU_STOP] = mainMenuManager.Load<Texture2D>("Textures\\MenuStop");

            aryRenderTargets[RENDER_ACTIVE_TEX] = new RenderTarget2D(GraphicsDevice, 1024, 1024, false, SurfaceFormat.Color, DepthFormat.None);
            aryRenderTargets[RENDER_CREATE_STRUCTURE] = new RenderTarget2D(GraphicsDevice, 1024, 1024, false, SurfaceFormat.Color, DepthFormat.None);
            #endregion

            // Create Main Menu
            int lineBorder = (int)(safeArea.Height * .01f);
            Rectangle buttonRect = new Rectangle(0, 0, (int)(safeArea.Width * .1f), (int)(safeArea.Height * .03f));
            Rectangle iconRect = new Rectangle(0, 0, (int)(safeArea.Width * .03f), (int)(safeArea.Height * .05f));

            #region MAP MANAGER HUD
            hudMapManager = new HUD(spriteBatch, new Rectangle(safeArea.X, safeArea.Y, safeArea.Width, (int)(.15f * safeArea.Height)), 10);

            // *** System Window
            hudMapManager.CreateWindow("System", hudMapManager.Rect.Width, hudMapManager.Rect.Height, 2, Alignment.None, Alignment.None);

            // Background
            hudMapManager["System"].CreateImageField("Background", aryEffects[EFFECT_BASIC], aryTextures[MENU_DARK_GRAY],
                hudMapManager["System"].WndRect.Width, hudMapManager["System"].WndRect.Height, Color.White, Alignment.Center, Alignment.Center, false);

            // Toggle VCT (Viewing, Construction, Textures)
            hudMapManager["System"].CreateImageField("ToggleVCT", aryEffects[EFFECT_BASIC], aryTextures[MENU_WND_ARROW_DOWN],
                iconRect.Width, (int)(.25f * iconRect.Height), Color.White, Alignment.Min, Alignment.Max, true);

            // *** Main Window
            hudMapManager.CreateWindow("Main", (int)(.15f * hudMapManager.Rect.Width), hudMapManager.Rect.Height - 2 * hudMapManager.Border, 10, Alignment.Min, Alignment.Center);
            // Background
            hudMapManager["Main"].CreateImageField("Background", aryEffects[EFFECT_BASIC], aryTextures[MENU_MEDIUM_BLUE],
                hudMapManager["Main"].WndRect.Width, hudMapManager["Main"].WndRect.Height, Color.White, Alignment.Center, Alignment.Center, false);
            // Title
            hudMapManager["Main"].CreateTextField("Title", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL], "File",
                Color.White, Alignment.Center, Alignment.None, false);
            hudMapManager["Main"].ModifyField("Title", new Vector2(hudMapManager["Main"]["Title"].DrawRect.X, hudMapManager.Rect.Y + 1));
            hudMapManager["Main"].LineBorder = 10;
            hudMapManager["Main"].EnableLineTrack = true;
            // Load
            hudMapManager["Main"].CreateCustomField("Load", aryEffects[EFFECT_BASIC], aryTextures[MENU_DARK_GRAY],
                (int)(.5f * buttonRect.Width), (int)(.75f * buttonRect.Height), Color.White, aryFonts[FONTS_SMALL], "Load", Color.White,
                Alignment.None, Alignment.None, Alignment.Center, Alignment.Center, true);
            // Save
            hudMapManager["Main"].CreateCustomField("Save", aryEffects[EFFECT_BASIC], aryTextures[MENU_DARK_GRAY],
                (int)(.5f * buttonRect.Width), (int)(.75f * buttonRect.Height), Color.White, aryFonts[FONTS_SMALL], "Save", Color.White,
                Alignment.None, Alignment.None, Alignment.Center, Alignment.Center, true);
            
            hudMapManager["Main"].NewLine();            
            
            // Export
            hudMapManager["Main"].CreateCustomField("Export", aryEffects[EFFECT_BASIC], aryTextures[MENU_DARK_GRAY],
                (int)(.5f * buttonRect.Width), (int)(.75f * buttonRect.Height), Color.White, aryFonts[FONTS_SMALL], "Export", Color.White,
                Alignment.None, Alignment.None, Alignment.Center, Alignment.Center, true);

            // About
            hudMapManager["Main"].CreateCustomField("About", aryEffects[EFFECT_BASIC], aryTextures[MENU_DARK_GRAY],
                (int)(.5f * buttonRect.Width), (int)(.75f * buttonRect.Height), Color.White, aryFonts[FONTS_SMALL], "About", Color.White,
                Alignment.None, Alignment.None, Alignment.Center, Alignment.Center, true);

            hudMapManager["Main"].NewLine();
            
            // Exit
            hudMapManager["Main"].CreateCustomField("Exit", aryEffects[EFFECT_BASIC], aryTextures[MENU_DARK_GRAY],
                (int)(.5f * buttonRect.Width), (int)(.75f * buttonRect.Height), Color.White, aryFonts[FONTS_SMALL], "Exit", Color.White,
                Alignment.None, Alignment.None, Alignment.Center, Alignment.Center, true);
            // Help
            hudMapManager["Main"].CreateCustomField("Help", aryEffects[EFFECT_BASIC], aryTextures[MENU_DARK_GRAY],
                (int)(.5f * buttonRect.Width), (int)(.75f * buttonRect.Height), Color.White, aryFonts[FONTS_SMALL], "Help", Color.White,
                Alignment.None, Alignment.None, Alignment.Center, Alignment.Center, true);
            // *** Sectors Window
            hudMapManager.CreateWindow("Sectors", (int)(.15f * hudMapManager.Rect.Width), hudMapManager.Rect.Height - 2 * hudMapManager.Border, 15, Alignment.OneFourth, Alignment.Center);
            // Background
            hudMapManager["Sectors"].CreateImageField("Background", aryEffects[EFFECT_BASIC], aryTextures[MENU_MEDIUM_BLUE],
                hudMapManager["Sectors"].WndRect.Width, hudMapManager["Sectors"].WndRect.Height, Color.White, Alignment.Center, Alignment.Center, false);
            // Title
            hudMapManager["Sectors"].CreateTextField("Title", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL], "Sectors",
                Color.White, Alignment.Center, Alignment.None, false);
            hudMapManager["Sectors"].ModifyField("Title", new Vector2(hudMapManager["Sectors"]["Title"].DrawRect.X, hudMapManager.Rect.Y + 1));

            // New Sector
            hudMapManager["Sectors"].CreateCustomField("NewSector", aryEffects[EFFECT_BASIC], aryTextures[MENU_DARK_GRAY],
                Color.White, 2, aryFonts[FONTS_SMALL], "New Sector", Color.White, Alignment.Min, Alignment.Min, Alignment.Center, Alignment.Center, true);

            // Is Visible
            hudMapManager["Sectors"].CreateCustomField("IsVisible", aryEffects[EFFECT_BASIC], aryTextures[MENU_DARK_GRAY],
                Color.White, 2, aryFonts[FONTS_SMALL], "Is Visible", Color.White, Alignment.Max, Alignment.Min, Alignment.Center, Alignment.Center, true);

            // Vertices Title
            hudMapManager["Sectors"].CreateTextField("VerticesTitle", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL], "Vertex Buffer Size: ",
                Color.White, Alignment.Min, Alignment.Center, false);

            // Vertices Amount
            hudMapManager["Sectors"].CreateTextField("Vertices", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL], "0 MB",
                Color.White, Alignment.Max, Alignment.Center, false);

            // Previous Sector
            hudMapManager["Sectors"].CreateImageField("Previous", aryEffects[EFFECT_BASIC], aryTextures[MENU_ARROW_LEFT],
                (int)(.5f * iconRect.Width), (int)(.5f * iconRect.Height), Color.White, Alignment.Min, Alignment.Max, true);

            // Current Sector
            hudMapManager["Sectors"].CreateTextField("Current", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL], "0",
                Color.White, Alignment.Center, Alignment.Max, false);

            // Next Sector
            hudMapManager["Sectors"].CreateImageField("Next", aryEffects[EFFECT_BASIC], aryTextures[MENU_ARROW_RIGHT],
                hudMapManager["Sectors"]["Previous"].DrawRect.Width, hudMapManager["Sectors"]["Previous"].DrawRect.Height, Color.White, Alignment.Max, Alignment.Max, true);

            // *** Simulation Window
            hudMapManager.CreateWindow("Simulation", (int)(.25f * hudMapManager.Rect.Width), hudMapManager.Rect.Height - 2 * hudMapManager.Border, 5, Alignment.Center, Alignment.Center);
            // Background
            hudMapManager["Simulation"].CreateImageField("Background", aryEffects[EFFECT_BASIC], aryTextures[MENU_MEDIUM_BLUE],
                hudMapManager["Simulation"].WndRect.Width, hudMapManager["Simulation"].WndRect.Height, Color.White, Alignment.Center, Alignment.Center, false);
            // Title
            hudMapManager["Simulation"].CreateTextField("Title", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL], "Simulation",
                Color.White, Alignment.Center, Alignment.Below, false);
            hudMapManager["Simulation"].ModifyField("Title", new Vector2(hudMapManager["Simulation"]["Title"].DrawRect.X, hudMapManager.Rect.Y + 1));
            // Start Simulation
            hudMapManager["Simulation"].CreateCustomField("Start", aryEffects[EFFECT_BASIC], aryTextures[MENU_DARK_GRAY],
                Color.White, 2, aryFonts[FONTS_SMALL], "Start", Color.White, Alignment.Min, Alignment.Min, Alignment.Center, Alignment.Center, true);
            // Status Title
            hudMapManager["Simulation"].CreateTextField("StatusTitle", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL], "Status: ",
                Color.White, Alignment.Min, Alignment.Max, false);
            // Status
            hudMapManager["Simulation"].CreateTextField("Status", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL], "Normal", Color.White, Alignment.OneThird, Alignment.Max, false);
            // GC Title
            hudMapManager["Simulation"].CreateTextField("GCTitle", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL], "GC: ",
                Color.White, Alignment.Center, Alignment.Max, false);
            // GC
            hudMapManager["Simulation"].CreateTextField("GC", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL], " ", Color.White, Alignment.TwoThirds, Alignment.Max, false);

            // *** Object Info Window
            hudMapManager.CreateWindow("ObjectInfo", (int)(.25f * hudMapManager.Rect.Width), hudMapManager.Rect.Height - 2 * hudMapManager.Border, 5, Alignment.Max, Alignment.Center);
            // Background
            hudMapManager["ObjectInfo"].CreateImageField("Background", aryEffects[EFFECT_BASIC], aryTextures[MENU_MEDIUM_BLUE],
                hudMapManager["ObjectInfo"].WndRect.Width, hudMapManager["ObjectInfo"].WndRect.Height, Color.White, Alignment.Center, Alignment.Center, false);
            // Title
            hudMapManager["ObjectInfo"].CreateTextField("Title", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL], "Properties",
                Color.White, Alignment.Center, Alignment.Below, false);
            hudMapManager["ObjectInfo"].ModifyField("Title", new Vector2(hudMapManager["ObjectInfo"]["Title"].DrawRect.X, hudMapManager.Rect.Y + 1));

            // *** Guide Window
            hudMapManager.CreateWindow("Guide", (int)(.75f * safeArea.Width), (int)(.75f * safeArea.Height), 20, Alignment.Min, Alignment.None);
            hudMapManager["Guide"].WndRect.Y = safeArea.Y + hudMapManager.Rect.Height;
            hudMapManager["Guide"].IsVisible = false;
            // Background
            hudMapManager["Guide"].CreateImageField("Background", aryEffects[EFFECT_BASIC], aryTextures[MENU_GUIDE],
                hudMapManager["Guide"].WndRect.Width, hudMapManager["Guide"].WndRect.Height, Color.White, Alignment.None, Alignment.None, false);

            // *** About Window
            hudMapManager.CreateWindow("About", (int)(.75f * safeArea.Width), (int)(.75f * safeArea.Height), 20, Alignment.Min, Alignment.None);
            hudMapManager["About"].WndRect.Y = safeArea.Y + hudMapManager.Rect.Height;
            hudMapManager["About"].IsVisible = false;
            // Background
            hudMapManager["About"].CreateImageField("Background", aryEffects[EFFECT_BASIC], aryTextures[MENU_ABOUT],
                hudMapManager["About"].WndRect.Width, hudMapManager["About"].WndRect.Height, Color.White, Alignment.None, Alignment.None, false);


            // *** Quick Guide Window
            hudMapManager.CreateWindow("QuickGuide", (int)(.5f * safeArea.Width), (int)(.6f * safeArea.Height), 20, Alignment.Max, Alignment.None);
            hudMapManager["QuickGuide"].WndRect.Y = safeArea.Y + hudMapManager.Rect.Height;
            hudMapManager["QuickGuide"].IsVisible = false;
            // Background
            hudMapManager["QuickGuide"].CreateImageField("Background", aryEffects[EFFECT_BASIC], aryTextures[MENU_QUICK_GUIDE],
                hudMapManager["QuickGuide"].WndRect.Width, hudMapManager["QuickGuide"].WndRect.Height, Color.White, Alignment.None, Alignment.None, false);

            // *** Message Window
            hudMapManager.CreateWindow("Message", (int)(.5f * safeArea.Width), (int)(.5f * safeArea.Height), 20, Alignment.Center, Alignment.None);
            hudMapManager["Message"].WndRect.Y = safeArea.Y + 2 * hudMapManager.Rect.Height;
            hudMapManager["Message"].IsVisible = false;
            // Background
            hudMapManager["Message"].CreateImageField("Background", aryEffects[EFFECT_BASIC], aryTextures[MENU_DARK_GRAY],
                hudMapManager["Message"].WndRect.Width, hudMapManager["Message"].WndRect.Height, Color.White, Alignment.None, Alignment.None, false);
            // Text
            hudMapManager["Message"].CreateTextField("Text", aryEffects[EFFECT_BASIC], aryFonts[FONTS_MEDIUM], " ", Color.White, Alignment.Center, Alignment.Below, false);
            // Ok
            hudMapManager["Message"].CreateCustomField("Ok", aryEffects[EFFECT_BASIC], aryTextures[MENU_LIGHT_GRAY], Color.White, 5,
                aryFonts[FONTS_MEDIUM], "  Ok  ", Color.Black, Alignment.ThreeFourths, Alignment.Max, Alignment.Center, Alignment.Center, true);
            // Cancel
            hudMapManager["Message"].CreateCustomField("Cancel", aryEffects[EFFECT_BASIC], aryTextures[MENU_LIGHT_GRAY], Color.White, 5,
                aryFonts[FONTS_MEDIUM], "Cancel", Color.Black, Alignment.Max, Alignment.Max, Alignment.Center, Alignment.Center, true);

            // *** File Window
            hudMapManager.CreateWindow("File", (int)(.5f * safeArea.Width), (int)(.5f * safeArea.Height), 20, Alignment.Center, Alignment.None);
            hudMapManager["File"].WndRect.Y = safeArea.Y + hudMapManager.Rect.Height;
            hudMapManager["File"].IsVisible = false;
            hudMapManager["File"].LineBorder = 5;
            // Background
            hudMapManager["File"].CreateImageField("Background", aryEffects[EFFECT_BASIC], aryTextures[MENU_DARK_GRAY],
                hudMapManager["File"].WndRect.Width, hudMapManager["File"].WndRect.Height, Color.White, Alignment.None, Alignment.None, false);
            // Title
            hudMapManager["File"].CreateTextField("Title", aryEffects[EFFECT_BASIC], aryFonts[FONTS_MEDIUM], " ", Color.White, Alignment.Center, Alignment.Below, false);
            // Ok
            hudMapManager["File"].CreateCustomField("Ok", aryEffects[EFFECT_BASIC], aryTextures[MENU_LIGHT_GRAY], Color.White, 5,
                aryFonts[FONTS_MEDIUM], "  Ok  ", Color.Black, Alignment.ThreeFourths, Alignment.Max, Alignment.Center, Alignment.Center, true);
            // Cancel
            hudMapManager["File"].CreateCustomField("Cancel", aryEffects[EFFECT_BASIC], aryTextures[MENU_LIGHT_GRAY], Color.White, 5,
                aryFonts[FONTS_MEDIUM], "Cancel", Color.Black, Alignment.Max, Alignment.Max, Alignment.Center, Alignment.Center, true);
            #endregion

            #region VIEW HUD
            hudView = new HUD(spriteBatch, new Rectangle(safeArea.X, hudMapManager.Rect.Y + hudMapManager.Rect.Height, (int)(.125f * safeArea.Width), (int)(.125f * safeArea.Height)), 0);
            // Main Window
            hudView.CreateWindow("Main", hudView.Rect.Width, hudView.Rect.Height, 10, Alignment.Center, Alignment.Center);
            // Background
            hudView["Main"].CreateImageField("Background", aryEffects[EFFECT_BASIC], aryTextures[MENU_DARK_GRAY],
                hudView.Rect.Width, hudView.Rect.Height, Color.White, Alignment.Center, Alignment.Center, false);
            // Title
            hudView["Main"].CreateTextField("Title", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL], "Viewing",
                Color.White, Alignment.Max, Alignment.Below, false);

            hudView["Main"].EnableLineTrack = true;
            hudView["Main"].LineBorder = 10;
            hudView["Main"].NewLine(10);

            // Select Layer - Construction
            hudView["Main"].CreateImageField(LayerType.Construction.ToString(), aryEffects[EFFECT_BASIC], aryTextures[MENU_LAYER_CONSTRUCTION],
                (int)(.55f * iconRect.Width), (int)(.55f * iconRect.Height), Color.White, Alignment.None, Alignment.None, true);

            // Select Layer - Bound
            hudView["Main"].CreateImageField(LayerType.Bound.ToString(), aryEffects[EFFECT_BASIC], aryTextures[MENU_LAYER_BOUND],
                hudView["Main"][LayerType.Construction.ToString()].DrawRect.Width, hudView["Main"][LayerType.Construction.ToString()].DrawRect.Height,
                Color.Gray, Alignment.None, Alignment.None, true);

            // Select Layer - Light
            hudView["Main"].CreateImageField(LayerType.Light.ToString(), aryEffects[EFFECT_BASIC], aryTextures[MENU_LAYER_LIGHT],
                hudView["Main"][LayerType.Construction.ToString()].DrawRect.Width, hudView["Main"][LayerType.Construction.ToString()].DrawRect.Height,
                Color.Gray, Alignment.None, Alignment.None, true);

            // Select Layer - Location
            hudView["Main"].CreateImageField(LayerType.Location.ToString(), aryEffects[EFFECT_BASIC], aryTextures[MENU_LAYER_LOCATION],
                hudView["Main"][LayerType.Construction.ToString()].DrawRect.Width, hudView["Main"][LayerType.Construction.ToString()].DrawRect.Height,
                Color.Gray, Alignment.None, Alignment.None, true);

            hudView["Main"].NewLine();

            // Toggle Layer Visible - Construction
            hudView["Main"].CreateImageField("VisibleConstruction", aryEffects[EFFECT_BASIC], aryTextures[MENU_EYE],
                hudView["Main"][LayerType.Construction.ToString()].DrawRect.Width, (int)(.2f * iconRect.Height),
                Color.White, Alignment.None, Alignment.None, true);

            // Toggle Layer Visible - Bound
            hudView["Main"].CreateImageField("VisibleBound", aryEffects[EFFECT_BASIC], aryTextures[MENU_EYE],
                hudView["Main"][LayerType.Construction.ToString()].DrawRect.Width, (int)(.2f * iconRect.Height),
                Color.White, Alignment.None, Alignment.None, true);

            // Toggle Layer Visible - Lights
            hudView["Main"].CreateImageField("VisibleLight", aryEffects[EFFECT_BASIC], aryTextures[MENU_EYE],
                hudView["Main"][LayerType.Construction.ToString()].DrawRect.Width, (int)(.2f * iconRect.Height),
                Color.White, Alignment.None, Alignment.None, true);

            // Toggle Layer Visible - Location
            hudView["Main"].CreateImageField("VisibleLocation", aryEffects[EFFECT_BASIC], aryTextures[MENU_EYE],
                hudView["Main"][LayerType.Construction.ToString()].DrawRect.Width, hudView["Main"]["VisibleConstruction"].DrawRect.Height,
                Color.White, Alignment.None, Alignment.None, true);

            // System Window
            hudView.CreateWindow("System", (int)(.4f * iconRect.Width), (int)(.4f * iconRect.Height), 2, Alignment.Min, Alignment.Min);
            // Toggle Window Visible
            hudView["System"].CreateImageField("ToggleWindow", aryEffects[EFFECT_BASIC], aryTextures[MENU_EYE],
                hudView["System"].WndRect.Width, hudView["System"].WndRect.Height, Color.White, Alignment.Min, Alignment.Min, true);
            #endregion

            #region CONSTRUCTION HUD
            hudConstruction = new HUD(spriteBatch, new Rectangle(safeArea.X, hudView.Rect.Y + hudView.Rect.Height,
                (int)(.125f * safeArea.Width), (int)(.4f * safeArea.Height)), 0);
            // Main Window
            hudConstruction.CreateWindow("Main", hudConstruction.Rect.Width, hudConstruction.Rect.Height, 10, Alignment.Center, Alignment.Center);
            // Background
            hudConstruction["Main"].CreateImageField("Background", aryEffects[EFFECT_BASIC], aryTextures[MENU_DARK_GRAY],
                hudConstruction.Rect.Width, hudConstruction.Rect.Height, Color.White, Alignment.Center, Alignment.Center, false);
            // Title
            hudConstruction["Main"].CreateTextField("Title", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL], "Construction",
                Color.White, Alignment.Max, Alignment.Below, false);
            hudConstruction["Main"].EnableLineTrack = true;
            hudConstruction["Main"].LineBorder = 10;
            hudConstruction["Main"].NewLine(10);

            // Paint
            hudConstruction["Main"].CreateImageField("Paint", aryEffects[EFFECT_BASIC], aryTextures[MENU_PAINT],
                (int)(.5f * iconRect.Width), (int)(.5f * iconRect.Height), Color.White, Alignment.None, Alignment.None, true);

            // Pin Structures
            hudConstruction["Main"].CreateImageField("Pin", aryEffects[EFFECT_BASIC], aryTextures[MENU_PIN],
                hudConstruction["Main"]["Paint"].DrawRect.Width, hudConstruction["Main"]["Paint"].DrawRect.Height, Color.White, Alignment.None, Alignment.None, true);

            // Unpin Structures
            hudConstruction["Main"].CreateImageField("Unpin", aryEffects[EFFECT_BASIC], aryTextures[MENU_UNPIN],
                hudConstruction["Main"]["Paint"].DrawRect.Width, hudConstruction["Main"]["Paint"].DrawRect.Height, Color.White, Alignment.None, Alignment.None, true);

            // Vertex Snap
            hudConstruction["Main"].CreateImageField("VertexSnap", aryEffects[EFFECT_BASIC], aryTextures[MENU_VERTEX_SNAP],
                hudConstruction["Main"]["Paint"].DrawRect.Width, hudConstruction["Main"]["Paint"].DrawRect.Height, Color.White, Alignment.None, Alignment.None, true);

            // Link
            hudConstruction["Main"].CreateImageField("Link", aryEffects[EFFECT_BASIC], aryTextures[MENU_LINK_RELAY],
                hudConstruction["Main"]["Paint"].DrawRect.Width, hudConstruction["Main"]["Paint"].DrawRect.Height, Color.White, Alignment.None, Alignment.None, true);

            hudConstruction["Main"].NewLine();

            // Bound Box
            hudConstruction["Main"].CreateImageField(BoundType.Box.ToString(), aryEffects[EFFECT_BASIC], aryTextures[MENU_BOUND_BOX],
                (int)(.75f * iconRect.Width), (int)(.75f * iconRect.Height), Color.White, Alignment.None, Alignment.None, true);

            // Bound Sphere
            hudConstruction["Main"].CreateImageField(BoundType.Sphere.ToString(), aryEffects[EFFECT_BASIC], aryTextures[MENU_BOUND_SPHERE],
                hudConstruction["Main"][BoundType.Box.ToString()].DrawRect.Width, hudConstruction["Main"][BoundType.Box.ToString()].DrawRect.Height, Color.Gray, Alignment.None, Alignment.None, true);

            // Add Bound
            hudConstruction["Main"].CreateImageField("AddBound", aryEffects[EFFECT_BASIC], aryTextures[MENU_ADD_BOUND],
                hudConstruction["Main"][BoundType.Box.ToString()].DrawRect.Width, hudConstruction["Main"][BoundType.Box.ToString()].DrawRect.Height, Color.White, Alignment.None, Alignment.None, true);

            hudConstruction["Main"].NewLine();

            // Add Location
            hudConstruction["Main"].CreateImageField("AddLocation", aryEffects[EFFECT_BASIC], aryTextures[MENU_ADD_LOCATION],
                iconRect.Width, iconRect.Height, Color.White, Alignment.None, Alignment.None, true);

            // Add Spawn
            hudConstruction["Main"].CreateImageField("AddSpawn", aryEffects[EFFECT_BASIC], aryTextures[MENU_ADD_SPAWN],
                iconRect.Width, iconRect.Height, Color.White, Alignment.None, Alignment.None, true);

            // Add Relay
            hudConstruction["Main"].CreateImageField("AddRelay", aryEffects[EFFECT_BASIC], aryTextures[MENU_ADD_RELAY],
                iconRect.Width, iconRect.Height, Color.White, Alignment.None, Alignment.None, true);

            hudConstruction["Main"].NewLine();

            // Add Structure
            hudConstruction["Main"].CreateImageField("AddStructure", aryEffects[EFFECT_BASIC], aryTextures[MENU_ADD_STRUCTURE],
                iconRect.Width, iconRect.Height, Color.White, Alignment.None, Alignment.None, true);

            // Add Interactive
            hudConstruction["Main"].CreateImageField("AddInteractive", aryEffects[EFFECT_BASIC], aryTextures[MENU_ADD_INTERACTIVE],
                iconRect.Width, iconRect.Height, Color.White, Alignment.None, Alignment.None, true);

            hudConstruction["Main"].NewLine();

            // Add Light
            hudConstruction["Main"].CreateImageField("AddLight", aryEffects[EFFECT_BASIC], aryTextures[MENU_ADD_LIGHT],
                iconRect.Width, iconRect.Height, Color.White, Alignment.None, Alignment.None, true);

            // Bake Light
            hudConstruction["Main"].CreateImageField("BakeLight", aryEffects[EFFECT_BASIC], aryTextures[MENU_BAKE_LIGHT],
                iconRect.Width, iconRect.Height, Color.White, Alignment.None, Alignment.None, true);

            // *** System Window
            hudConstruction.CreateWindow("System", (int)(.4f * iconRect.Width), (int)(.4f * iconRect.Height), 2, Alignment.Min, Alignment.Min);
            // Toggle Window Visible
            hudConstruction["System"].CreateImageField("ToggleWindow", aryEffects[EFFECT_BASIC], aryTextures[MENU_LAYER_CONSTRUCTION],
                hudConstruction["System"].WndRect.Width, hudConstruction["System"].WndRect.Height, Color.White, Alignment.Min, Alignment.Min, true);
            #endregion

            #region TEXTURE HUD
            hudTexture = new HUD(spriteBatch, new Rectangle(safeArea.X, hudConstruction.Rect.Y + hudConstruction.Rect.Height,
                (int)(.125f * safeArea.Width), (int)(.3f * safeArea.Height)), 0);
            // Main Window
            hudTexture.CreateWindow("Main", hudTexture.Rect.Width, hudTexture.Rect.Height, 30, Alignment.Center, Alignment.Center);
            // Background
            hudTexture["Main"].CreateImageField("Background", aryEffects[EFFECT_BASIC], aryTextures[MENU_DARK_GRAY],
                hudTexture["Main"].WndRect.Width, hudTexture["Main"].WndRect.Height, Color.White, Alignment.Center, Alignment.Center, false);
            // Title
            hudTexture["Main"].CreateTextField("Title", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL], "Textures",
                Color.White, Alignment.Max, Alignment.Below, false);
            // Active Texture
            hudTexture["Main"].CreateImageField("ActiveTex", aryEffects[EFFECT_BASIC], (Texture2D)aryRenderTargets[RENDER_ACTIVE_TEX],
                (int)(hudTexture["Main"].WndRect.Width * .55f), (int)(hudTexture["Main"].WndRect.Height * .35f), Color.White,
                Alignment.Center, Alignment.Min, true);
            hudTexture["Main"].Border = 10;
            // Texture Preview
            hudTexture["Main"].CreateImageField("TexPreview", aryEffects[EFFECT_TEX_HIGHLIGHT], aryTextures[MENU_PALETTE_1],
                (int)(hudTexture["Main"].WndRect.Width * .7f), (int)(hudTexture["Main"].WndRect.Height * .4f), Color.White,
                Alignment.Center, Alignment.Max, true);
            // Previous palette
            hudTexture["Main"].CreateImageField("PreviousPalette", aryEffects[EFFECT_BASIC], aryTextures[MENU_ARROW_LEFT],
                (int)(.25f * iconRect.Width), (int)(.25f * iconRect.Height), Color.White, Alignment.Min, Alignment.Max, true);
            // Next palette
            hudTexture["Main"].CreateImageField("NextPalette", aryEffects[EFFECT_BASIC], aryTextures[MENU_ARROW_RIGHT],
                hudTexture["Main"]["PreviousPalette"].DrawRect.Width, hudTexture["Main"]["PreviousPalette"].DrawRect.Height,
                Color.White, Alignment.Max, Alignment.Max, true);

            // *** System Window
            hudTexture.CreateWindow("System", (int)(.4f * iconRect.Width), (int)(.4f * iconRect.Height), 2, Alignment.Min, Alignment.Min);
            // Toggle Window Visible
            hudTexture["System"].CreateImageField("ToggleWindow", aryEffects[EFFECT_BASIC], aryTextures[MENU_PALETTE_1],
                hudTexture["System"].WndRect.Width, hudTexture["System"].WndRect.Height, Color.White, Alignment.Min, Alignment.Min, true);
            #endregion

            #region ANIMATION HUD
            hudAnimation = new HUD(spriteBatch, new Rectangle(safeArea.Width - (int)(.155f * safeArea.Width), hudMapManager.Rect.Y + hudMapManager.Rect.Height,
                (int)(.15f * safeArea.Width), safeArea.Height - hudMapManager.Rect.Height), 0);
            hudAnimation.IsVisible = false;
            // *** Animation Control
            hudAnimation.CreateWindow("AnimationControl", hudAnimation.Rect.Width, (int)(.35f * hudAnimation.Rect.Height), 10, Alignment.Min, Alignment.Min);
            // Create Background
            hudAnimation["AnimationControl"].CreateImageField("Background", aryEffects[EFFECT_BASIC], aryTextures[MENU_DARK_PURPLE],
                hudAnimation["AnimationControl"].WndRect.Width, hudAnimation["AnimationControl"].WndRect.Height, Color.White,
                Alignment.Center, Alignment.Center, false);
            hudAnimation["AnimationControl"].EnableLineTrack = true;
            hudAnimation["AnimationControl"].LineBorder = 8;
            
            // New Animation
            hudAnimation["AnimationControl"].CreateCustomField("NewAnimation", aryEffects[EFFECT_BASIC], aryTextures[MENU_DARK_GRAY],
                buttonRect.Width, buttonRect.Height, Color.White, aryFonts[FONTS_SMALL], "New Animation", Color.White,
                Alignment.None, Alignment.None, Alignment.Center, Alignment.Center, true);
            // Delete Animation
            hudAnimation["AnimationControl"].CreateImageField("DeleteAnimation", aryEffects[EFFECT_BASIC], aryTextures[MENU_DELETE],
                buttonRect.Height, buttonRect.Height, Color.White, Alignment.None, Alignment.None, true);

            hudAnimation["AnimationControl"].NewLine();

            // New Frame
            hudAnimation["AnimationControl"].CreateCustomField("NewFrame", aryEffects[EFFECT_BASIC], aryTextures[MENU_DARK_GRAY],
                buttonRect.Width, buttonRect.Height, Color.White, aryFonts[FONTS_SMALL], "New Frame", Color.White,
                Alignment.None, Alignment.None, Alignment.Center, Alignment.Center, true);
            // Delete Frame
            hudAnimation["AnimationControl"].CreateImageField("DeleteFrame", aryEffects[EFFECT_BASIC], aryTextures[MENU_DELETE],
                buttonRect.Height, buttonRect.Height, Color.White, Alignment.None, Alignment.None, true);

            hudAnimation["AnimationControl"].NewLine();

            // Link Structure
            hudAnimation["AnimationControl"].CreateCustomField("LinkStructure", aryEffects[EFFECT_BASIC], aryTextures[MENU_DARK_GRAY],
                buttonRect.Width, buttonRect.Height, Color.White, aryFonts[FONTS_SMALL], "Link Object", Color.White,
                Alignment.None, Alignment.None, Alignment.Center, Alignment.Center, true);
            // Unlink Structure
            hudAnimation["AnimationControl"].CreateImageField("UnlinkStructure", aryEffects[EFFECT_BASIC], aryTextures[MENU_DELETE],
                buttonRect.Height, buttonRect.Height, Color.White, Alignment.None, Alignment.None, true);

            hudAnimation["AnimationControl"].NewLine();
            
            // Apply State
            hudAnimation["AnimationControl"].CreateCustomField("ApplyState", aryEffects[EFFECT_BASIC], aryTextures[MENU_DARK_GRAY],
                (int)(.5f * buttonRect.Width), (int)(1.8f * buttonRect.Height), Color.White, aryFonts[FONTS_SMALL], "Apply\nState",
                Color.White, Alignment.Min, Alignment.Max, Alignment.Center, Alignment.Center, true);
            // Auto State
            hudAnimation["AnimationControl"].CreateCustomField("AutoState", aryEffects[EFFECT_BASIC], aryTextures[MENU_DARK_GRAY],
                (int)(.5f * buttonRect.Width), (int)(1.8f * buttonRect.Height), Color.White, aryFonts[FONTS_SMALL], " Auto\nState",
                Color.White, Alignment.OneThird, Alignment.Max, Alignment.Center, Alignment.Center, true);

            hudAnimation["AnimationControl"].NewLine();

            // Play
            hudAnimation["AnimationControl"].CreateImageField("Play", aryEffects[EFFECT_BASIC], aryTextures[MENU_PLAY],
                (int)(.4f * buttonRect.Width), (int)(1.5f * buttonRect.Height), Color.White, Alignment.None, Alignment.None, true);

            // Pause
            hudAnimation["AnimationControl"].CreateImageField("Pause", aryEffects[EFFECT_BASIC], aryTextures[MENU_PAUSE],
                hudAnimation["AnimationControl"]["Play"].DrawRect.Width, hudAnimation["AnimationControl"]["Play"].DrawRect.Height, Color.White, Alignment.None, Alignment.None, true);

            // Stop
            hudAnimation["AnimationControl"].CreateImageField("Stop", aryEffects[EFFECT_BASIC], aryTextures[MENU_STOP],
                hudAnimation["AnimationControl"]["Play"].DrawRect.Width, hudAnimation["AnimationControl"]["Play"].DrawRect.Height, Color.White, Alignment.None, Alignment.None, true);

            // *** Animation Select
            hudAnimation.CreateWindow("AnimationSelect", hudAnimation.Rect.Width, (int)(.125f * hudAnimation.Rect.Height), 7, Alignment.None, Alignment.Min);
            hudAnimation["AnimationSelect"].WndRect.Y = hudAnimation["AnimationControl"].WndRect.Y + hudAnimation["AnimationControl"].WndRect.Height;
            // Background
            hudAnimation["AnimationSelect"].CreateImageField("Background", aryEffects[EFFECT_BASIC], aryTextures[MENU_MEDIUM_BLUE],
                hudAnimation["AnimationSelect"].WndRect.Width, hudAnimation["AnimationSelect"].WndRect.Height, Color.White,
                Alignment.Center, Alignment.Center, false);
            hudAnimation["AnimationSelect"].EnableLineTrack = true;
            hudAnimation["AnimationSelect"].LineBorder = 7;

            // *** State Select
            hudAnimation.CreateWindow("StateSelect", hudAnimation.Rect.Width, (int)(.25f * hudAnimation.Rect.Height), 6, Alignment.None, Alignment.Min);
            hudAnimation["StateSelect"].WndRect.Y = hudAnimation["AnimationSelect"].WndRect.Y + hudAnimation["AnimationSelect"].WndRect.Height;
            // Background
            hudAnimation["StateSelect"].CreateImageField("Background", aryEffects[EFFECT_BASIC], aryTextures[MENU_ANIMATION],
                hudAnimation["StateSelect"].WndRect.Width, hudAnimation["StateSelect"].WndRect.Height, Color.White, Alignment.None, Alignment.None, false);
            
            // *** Frame Select
            hudAnimation.CreateWindow("FrameSelect", hudAnimation.Rect.Width, (int)(.05f * hudAnimation.Rect.Height), 6, Alignment.None, Alignment.Min);
            hudAnimation["FrameSelect"].WndRect.Y = hudAnimation["StateSelect"].WndRect.Y + hudAnimation["StateSelect"].WndRect.Height;
            // Background
            hudAnimation["FrameSelect"].CreateImageField("Background", aryEffects[EFFECT_BASIC], aryTextures[MENU_ANIMATION],
                hudAnimation["FrameSelect"].WndRect.Width, hudAnimation["FrameSelect"].WndRect.Height, Color.White, Alignment.None, Alignment.None, false);
            // Ticker
            hudAnimation["FrameSelect"].CreateImageField("Ticker", aryEffects[EFFECT_BASIC], aryTextures[MENU_BLUE_GRAY],
                (int)(.1f * iconRect.Width), hudAnimation["FrameSelect"].WndRect.Height, Color.White, Alignment.None, Alignment.None, false);
            
            // *** Time Control
            hudAnimation.CreateWindow("TimeControl", hudAnimation.Rect.Width, (int)(.05f * hudAnimation.Rect.Height), 6, Alignment.None, Alignment.Min);
            hudAnimation["TimeControl"].WndRect.Y = hudAnimation["FrameSelect"].WndRect.Y + hudAnimation["FrameSelect"].WndRect.Height;
            // Background
            hudAnimation["TimeControl"].CreateImageField("Background", aryEffects[EFFECT_BASIC], aryTextures[MENU_DARK_GRAY],
                hudAnimation["TimeControl"].WndRect.Width, hudAnimation["TimeControl"].WndRect.Height, Color.White,
                Alignment.Center, Alignment.Center, false);
            // Button Lessen Time
            hudAnimation["TimeControl"].CreateImageField("LessenTime", aryEffects[EFFECT_BASIC], aryTextures[MENU_MINUS],
                (int)(.4f * iconRect.Height), (int)(.4f * iconRect.Height),
                Color.White, Alignment.Min, Alignment.Max, true);
            // Animation Length
            hudAnimation["TimeControl"].CreateTextField("Length", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL], " ",
                Color.White, Alignment.Center, Alignment.Max, false);
            // Button Increase Time
            hudAnimation["TimeControl"].CreateImageField("IncreaseTime", aryEffects[EFFECT_BASIC], aryTextures[MENU_PLUS],
                hudAnimation["TimeControl"]["LessenTime"].DrawRect.Width, hudAnimation["TimeControl"]["LessenTime"].DrawRect.Height,
                Color.White, Alignment.Max, Alignment.Max, true);
            hudAnimation["TimeControl"].Border = 0;

            // Toggle Animations
            hudMapManager["System"].CreateImageField("ToggleAnimations", aryEffects[EFFECT_BASIC], aryTextures[MENU_WND_ARROW_DOWN],
                iconRect.Width, (int)(.25f * iconRect.Height), Color.White, Alignment.None, Alignment.Max, true);
            hudMapManager["System"].ModifyField("ToggleAnimations", new Vector2(hudAnimation.Rect.X, hudMapManager["System"]["ToggleAnimations"].DrawRect.Y));
            #endregion

            #region TRANSFORMATION HUD
            hudTransform = new HUD(spriteBatch, new Rectangle(safeArea.Width - (int)(safeArea.Width * .2f), safeArea.Height - (int)(safeArea.Height * .2f),
                (int)(safeArea.Width * .2f), (int)(safeArea.Height * .2f)), 0);
            // Main Window
            hudTransform.CreateWindow("Main", hudTransform.Rect.Width, hudTransform.Rect.Height, 30, Alignment.Center, Alignment.Center);
            // Background
            hudTransform["Main"].CreateImageField("Background", aryEffects[EFFECT_BASIC], aryTextures[MENU_DARK_GRAY],
                hudTransform.Rect.Width, hudTransform.Rect.Height, Color.White, Alignment.Center, Alignment.Center, false);
            // Title
            hudTransform["Main"].CreateTextField("Title", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL], "Transformations",
                Color.White, Alignment.Max, Alignment.Below, false);
            // Increase Height
            hudTransform["Main"].CreateImageField("IncreaseHeight", aryEffects[EFFECT_BASIC], aryTextures[MENU_ARROW_UP],
                iconRect.Width, (int)(.8f * iconRect.Height), Color.White,
                Alignment.Center, Alignment.Min, true);
            // Decrease Height
            hudTransform["Main"].CreateImageField("DecreaseHeight", aryEffects[EFFECT_BASIC], aryTextures[MENU_ARROW_DOWN],
                hudTransform["Main"]["IncreaseHeight"].DrawRect.Width, hudTransform["Main"]["IncreaseHeight"].DrawRect.Height, Color.White,
                Alignment.Center, Alignment.Max, true);
            // Decrease Width
            hudTransform["Main"].CreateImageField("DecreaseWidth", aryEffects[EFFECT_BASIC], aryTextures[MENU_ARROW_LEFT],
                (int)(.8f * iconRect.Width), iconRect.Height, Color.White,
                Alignment.Min, Alignment.Center, true);
            // Increase Width
            hudTransform["Main"].CreateImageField("IncreaseWidth", aryEffects[EFFECT_BASIC], aryTextures[MENU_ARROW_RIGHT],
                hudTransform["Main"]["DecreaseWidth"].DrawRect.Width, hudTransform["Main"]["DecreaseWidth"].DrawRect.Height, Color.White,
                Alignment.Max, Alignment.Center, true);

            // *** System Window
            hudTransform.CreateWindow("System", (int)(.4f * iconRect.Width), (int)(.4f * iconRect.Height), 2, Alignment.Max, Alignment.Max);
            // Toggle Window Visible
            hudTransform["System"].CreateImageField("ToggleWindow", aryEffects[EFFECT_BASIC], aryTextures[MENU_SCALE],
                hudTransform["System"].WndRect.Width, hudTransform["System"].WndRect.Height, Color.White, Alignment.Max, Alignment.Max, true);
            #endregion

            #region CREATE STRUCTURE HUD
            hudCreateStructure = new HUD(spriteBatch, new Rectangle(hudView.Rect.X + hudView.Rect.Width,
                hudView.Rect.Y, (int)(.75f * (safeArea.Width - hudConstruction.Rect.Width)), (int)(.75f * (safeArea.Height - hudMapManager.Rect.Height))), 10);
            // Preview Window
            hudCreateStructure.CreateWindow("Preview", hudCreateStructure.Rect.Width, hudCreateStructure.Rect.Height, 0, Alignment.Center, Alignment.Center);
            // Background
            hudCreateStructure["Preview"].CreateImageField("Background", aryEffects[EFFECT_BASIC], aryRenderTargets[RENDER_CREATE_STRUCTURE],
                hudCreateStructure["Preview"].WndRect.Width, hudCreateStructure["Preview"].WndRect.Height, Color.White, Alignment.Center, Alignment.Center, false);

            // BaseType Window
            hudCreateStructure.CreateWindow("BaseType", (int)(.4f * hudCreateStructure.Rect.Width),
                (int)(hudCreateStructure.Rect.Height * .2f), 10, Alignment.Min, Alignment.Min);
            // Background
            hudCreateStructure["BaseType"].CreateImageField("Background", aryEffects[EFFECT_BASIC], aryTextures[MENU_DARK_GRAY],
                hudCreateStructure["BaseType"].WndRect.Width, hudCreateStructure["BaseType"].WndRect.Height, Color.White, Alignment.Center, Alignment.Center, false);
            // Title
            hudCreateStructure["BaseType"].CreateTextField("Title", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL], "Select Base",
                Color.White, Alignment.Center, Alignment.Min, false);
            hudCreateStructure["BaseType"].EnableLineTrack = true;
            hudCreateStructure["BaseType"].LineBorder = 10;
            hudCreateStructure["BaseType"].NewLine(hudCreateStructure["BaseType"]["Title"].DrawRect.Height);
            // Plane Type
            hudCreateStructure["BaseType"].CreateImageField("Plane", aryEffects[EFFECT_BASIC], aryTextures[MENU_BASE_WALL],
                (int)(.5f * iconRect.Width), (int)(.5f * iconRect.Height), Color.White, Alignment.None, Alignment.None, true);
            // Triangle Type
            hudCreateStructure["BaseType"].CreateImageField("Triangle", aryEffects[EFFECT_BASIC], aryTextures[MENU_BASE_CONE],
                hudCreateStructure["BaseType"]["Plane"].DrawRect.Width, hudCreateStructure["BaseType"]["Plane"].DrawRect.Height,
                Color.Gray, Alignment.None, Alignment.None, true);
            // Wall Type
            hudCreateStructure["BaseType"].CreateImageField("Wall", aryEffects[EFFECT_BASIC], aryTextures[MENU_BASE_WALL],
                (int)(.5f * iconRect.Width), (int)(.5f * iconRect.Height), Color.White, Alignment.None, Alignment.None, true);
            // Cylinder Type
            hudCreateStructure["BaseType"].CreateImageField("Cylinder", aryEffects[EFFECT_BASIC], aryTextures[MENU_BASE_CYLINDER],
                hudCreateStructure["BaseType"]["Wall"].DrawRect.Width, hudCreateStructure["BaseType"]["Wall"].DrawRect.Height,
                Color.Gray, Alignment.None, Alignment.None, true);
            // Cube Type
            hudCreateStructure["BaseType"].CreateImageField("Cube", aryEffects[EFFECT_BASIC], aryTextures[MENU_BASE_BOX],
                hudCreateStructure["BaseType"]["Wall"].DrawRect.Width, hudCreateStructure["BaseType"]["Wall"].DrawRect.Height,
                Color.Gray, Alignment.None, Alignment.None, true);
            // Sphere Type
            hudCreateStructure["BaseType"].CreateImageField("Sphere", aryEffects[EFFECT_BASIC], aryTextures[MENU_BASE_SPHERE],
                hudCreateStructure["BaseType"]["Wall"].DrawRect.Width, hudCreateStructure["BaseType"]["Wall"].DrawRect.Height,
                Color.Gray, Alignment.None, Alignment.None, true);
            // Cone Type
            hudCreateStructure["BaseType"].CreateImageField("Cone", aryEffects[EFFECT_BASIC], aryTextures[MENU_BASE_CONE],
                hudCreateStructure["BaseType"]["Wall"].DrawRect.Width, hudCreateStructure["BaseType"]["Wall"].DrawRect.Height,
                Color.Gray, Alignment.None, Alignment.None, true);

            hudCreateStructure["BaseType"].NewLine();

            // Powerplant Type
            hudCreateStructure["BaseType"].CreateImageField("PowerPlant1", aryEffects[EFFECT_BASIC], aryTextures[MENU_BASE_CONE],
                hudCreateStructure["BaseType"]["Wall"].DrawRect.Width, hudCreateStructure["BaseType"]["Wall"].DrawRect.Height,
                Color.Gray, Alignment.None, Alignment.None, true);

            // FuturePillar Type
            hudCreateStructure["BaseType"].CreateImageField("FuturePillar", aryEffects[EFFECT_BASIC], aryTextures[MENU_BASE_CONE],
                hudCreateStructure["BaseType"]["Wall"].DrawRect.Width, hudCreateStructure["BaseType"]["Wall"].DrawRect.Height,
                Color.Gray, Alignment.None, Alignment.None, true);

            // Generator Type
            hudCreateStructure["BaseType"].CreateImageField("Generator", aryEffects[EFFECT_BASIC], aryTextures[MENU_BASE_CONE],
                hudCreateStructure["BaseType"]["Wall"].DrawRect.Width, hudCreateStructure["BaseType"]["Wall"].DrawRect.Height,
                Color.Gray, Alignment.None, Alignment.None, true);

            // GrateWindow Type
            hudCreateStructure["BaseType"].CreateImageField("GrateWindow", aryEffects[EFFECT_BASIC], aryTextures[MENU_BASE_CONE],
                hudCreateStructure["BaseType"]["Wall"].DrawRect.Width, hudCreateStructure["BaseType"]["Wall"].DrawRect.Height,
                Color.Gray, Alignment.None, Alignment.None, true);

            // Axis Window
            hudCreateStructure.CreateWindow("Axis", (int)(.25f * hudCreateStructure.Rect.Width),
                (int)(hudCreateStructure.Rect.Height * .1f), 5, Alignment.Max, Alignment.Min);
            // Background
            hudCreateStructure["Axis"].CreateImageField("Axis", aryEffects[EFFECT_BASIC], aryTextures[MENU_DARK_GRAY],
                hudCreateStructure["Axis"].WndRect.Width, hudCreateStructure["Axis"].WndRect.Height, Color.White, Alignment.Center, Alignment.Center, false);
            // Title
            hudCreateStructure["Axis"].CreateTextField("Title", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL], "Select Affected Axis",
                Color.White, Alignment.Center, Alignment.Min, false);
            // X
            hudCreateStructure["Axis"].CreateCustomField("X", aryEffects[EFFECT_BASIC], aryTextures[MENU_LIGHT_GRAY], Color.White,
                2, aryFonts[FONTS_SMALL], " X ", Color.Black, Alignment.OneFourth, Alignment.ThreeFourths, Alignment.Center, Alignment.Center, true);
            // Y
            hudCreateStructure["Axis"].CreateCustomField("Y", aryEffects[EFFECT_BASIC], aryTextures[MENU_LIGHT_GRAY], Color.White,
                2, aryFonts[FONTS_SMALL], " Y ", Color.Black, Alignment.Center, Alignment.ThreeFourths, Alignment.Center, Alignment.Center, true);
            // Z
            hudCreateStructure["Axis"].CreateCustomField("Z", aryEffects[EFFECT_BASIC], aryTextures[MENU_LIGHT_GRAY], Color.White, 
                2, aryFonts[FONTS_SMALL], " Z ", Color.Black, Alignment.ThreeFourths, Alignment.ThreeFourths, Alignment.Center, Alignment.Center, true);

            // Protrusion Window
            hudCreateStructure.CreateWindow("Protrusion", hudCreateStructure["Axis"].WndRect.Width,
                (int)(hudCreateStructure.Rect.Height * .1f), 5, Alignment.Max, Alignment.None);
            hudCreateStructure["Protrusion"].WndRect.Y = hudCreateStructure["Axis"].WndRect.Y + hudCreateStructure["Axis"].WndRect.Height;
            // Background
            hudCreateStructure["Protrusion"].CreateImageField("Background", aryEffects[EFFECT_BASIC], aryTextures[MENU_DARK_GRAY],
                hudCreateStructure["Protrusion"].WndRect.Width, hudCreateStructure["Protrusion"].WndRect.Height, Color.White, Alignment.Center, Alignment.Center, false);
            // Concave Title
            hudCreateStructure["Protrusion"].CreateTextField("ConcaveTitle", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL], "Concave",
                Color.White, Alignment.Min, Alignment.Min, false);
            // Concave
            hudCreateStructure["Protrusion"].CreateImageField("Concave", aryEffects[EFFECT_BASIC], aryTextures[MENU_MINUS],
                (int)(.4f * iconRect.Height), (int)(.4f * iconRect.Height), Color.White, Alignment.Min, Alignment.Max, true);
            // Amount
            hudCreateStructure["Protrusion"].CreateTextField("Amount", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL], structProtrusion.ToString(),
                Color.Wheat, Alignment.Center, Alignment.Min, false);
            // Convex Title
            hudCreateStructure["Protrusion"].CreateTextField("ConvexTitle", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL], "Convex",
                Color.White, Alignment.Max, Alignment.Min, false);
            // Convex
            hudCreateStructure["Protrusion"].CreateImageField("Convex", aryEffects[EFFECT_BASIC], aryTextures[MENU_PLUS],
                hudCreateStructure["Protrusion"]["Concave"].DrawRect.Width, hudCreateStructure["Protrusion"]["Concave"].DrawRect.Height,
                Color.White, Alignment.Max, Alignment.Max, true);
            // Line
            hudCreateStructure["Protrusion"].CreateImageField("Line", aryEffects[EFFECT_BASIC], aryTextures[MENU_LIGHT_GRAY],
                hudCreateStructure["Protrusion"].WndRect.Width - 2 * (hudCreateStructure["Protrusion"]["Convex"].DrawRect.Width + hudCreateStructure["Protrusion"].Border),
                3, Color.White, Alignment.Center, Alignment.ThreeFourths, false);
            // Ticker
            hudCreateStructure["Protrusion"].CreateImageField("Ticker", aryEffects[EFFECT_BASIC], aryTextures[MENU_BLUE_GRAY],
                (int)(.2f * iconRect.Height), (int)(.4f * iconRect.Height), Color.White, Alignment.Center, Alignment.Max, false);

            // Roughness Window
            hudCreateStructure.CreateWindow("Roughness", hudCreateStructure["Protrusion"].WndRect.Width,
                (int)(hudCreateStructure.Rect.Height * .1f), 5, Alignment.Max, Alignment.None);
            hudCreateStructure["Roughness"].WndRect.Y = hudCreateStructure["Protrusion"].WndRect.Y + hudCreateStructure["Protrusion"].WndRect.Height;
            // Background
            hudCreateStructure["Roughness"].CreateImageField("Background", aryEffects[EFFECT_BASIC], aryTextures[MENU_DARK_GRAY],
                hudCreateStructure["Roughness"].WndRect.Width, hudCreateStructure["Roughness"].WndRect.Height, Color.White, Alignment.Center, Alignment.Center, false);
            // Smooth Title
            hudCreateStructure["Roughness"].CreateTextField("SmoothTitle", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL], "Smooth",
                Color.White, Alignment.Min, Alignment.Min, false);
            // Smooth
            hudCreateStructure["Roughness"].CreateImageField("Smooth", aryEffects[EFFECT_BASIC], aryTextures[MENU_MINUS],
                (int)(.4f * iconRect.Height), (int)(.4f * iconRect.Height), Color.White, Alignment.Min, Alignment.Max, true);
            // Amount
            hudCreateStructure["Roughness"].CreateTextField("Amount", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL], structProtrusion.ToString(),
                Color.Wheat, Alignment.Center, Alignment.Min, false);
            // Rough Title
            hudCreateStructure["Roughness"].CreateTextField("RoughTitle", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL], "Rough",
                Color.White, Alignment.Max, Alignment.Min, false);
            // Rough
            hudCreateStructure["Roughness"].CreateImageField("Rough", aryEffects[EFFECT_BASIC], aryTextures[MENU_PLUS],
                hudCreateStructure["Roughness"]["Smooth"].DrawRect.Width, hudCreateStructure["Roughness"]["Smooth"].DrawRect.Height,
                Color.White, Alignment.Max, Alignment.Max, true);
            // Line
            hudCreateStructure["Roughness"].CreateImageField("Line", aryEffects[EFFECT_BASIC], aryTextures[MENU_LIGHT_GRAY],
                hudCreateStructure["Roughness"].WndRect.Width - 2 * (hudCreateStructure["Roughness"]["Smooth"].DrawRect.Width + hudCreateStructure["Roughness"].Border),
                3, Color.White, Alignment.Center, Alignment.ThreeFourths, false);
            // Ticker
            hudCreateStructure["Roughness"].CreateImageField("Ticker", aryEffects[EFFECT_BASIC], aryTextures[MENU_BLUE_GRAY],
                (int)(.2f * iconRect.Height), (int)(.4f * iconRect.Height), Color.White, Alignment.Center, Alignment.Max, false);

            // Confirmation Window
            hudCreateStructure.CreateWindow("Confirmation", (int)(.4f * hudCreateStructure.Rect.Width),
                (int)(hudCreateStructure.Rect.Height * .2f), 10, Alignment.Max, Alignment.Max);
            // Ok
            hudCreateStructure["Confirmation"].CreateCustomField("Ok", aryEffects[EFFECT_BASIC], aryTextures[MENU_DARK_GRAY], Color.White,
                4, aryFonts[FONTS_LARGE], "   Ok   ", Color.White, Alignment.Min, Alignment.Max, Alignment.Center, Alignment.Center, true);
            // Cancel
            hudCreateStructure["Confirmation"].CreateCustomField("Cancel", aryEffects[EFFECT_BASIC], aryTextures[MENU_DARK_GRAY], Color.White,
                4, aryFonts[FONTS_LARGE], " Cancel ", Color.White, Alignment.Max, Alignment.Max, Alignment.Center, Alignment.Center, true);
            #endregion

            #region TRIGGER HUD
            hudTrigger = new HUD(spriteBatch, new Rectangle(hudView.Rect.X + hudView.Rect.Width,
                hudView.Rect.Y, (int)(.4f * safeArea.Width), (int)(.4f * safeArea.Height)), 0);
            hudTrigger.IsVisible = false;
            // Toggle Trigger - In Map Manager
            hudMapManager["System"].CreateImageField("ToggleTrigger", aryEffects[EFFECT_BASIC], aryTextures[MENU_WND_ARROW_DOWN],
                iconRect.Width, (int)(.25f * iconRect.Height), Color.White, Alignment.None, Alignment.Max, true);
            hudMapManager["System"].ModifyField("ToggleTrigger", new Vector2(hudTrigger.Rect.X, hudMapManager["System"]["ToggleTrigger"].DrawRect.Y));
 
            // ** Trigger Select Window
            hudTrigger.CreateWindow("TriggerSelect", hudTrigger.Rect.Width, (int)(.75f * hudTrigger.Rect.Height), 20, Alignment.Center, Alignment.Min);
            // Background
            hudTrigger["TriggerSelect"].CreateImageField("Background", aryEffects[EFFECT_BASIC], aryTextures[MENU_LIGHT_GRAY],
                hudTrigger["TriggerSelect"].WndRect.Width, hudTrigger["TriggerSelect"].WndRect.Height, Color.White, Alignment.None, Alignment.None, false);
            hudTrigger["TriggerSelect"].LineBorder = 10;

            // ** Main Window
            hudTrigger.CreateWindow("Main", hudTrigger.Rect.Width, (int)(.25f * hudTrigger.Rect.Height), 20, Alignment.Center, Alignment.Max);
            // Background
            hudTrigger["Main"].CreateImageField("Background", aryEffects[EFFECT_BASIC], aryTextures[MENU_LIGHT_GRAY],
                hudTrigger["Main"].WndRect.Width, hudTrigger["Main"].WndRect.Height, Color.White, Alignment.None, Alignment.None, false);
            // New Trigger
            hudTrigger["Main"].CreateCustomField("NewTrigger", aryEffects[EFFECT_BASIC], aryTextures[MENU_DARK_GRAY], buttonRect.Width,
                buttonRect.Height, Color.White, aryFonts[FONTS_SMALL], "New Trigger", Color.White, Alignment.Min, Alignment.Max, Alignment.Center, Alignment.Center, true);
            // Delete Trigger
            hudTrigger["Main"].CreateImageField("DeleteTrigger", aryEffects[EFFECT_BASIC], aryTextures[MENU_DELETE], buttonRect.Height,
                buttonRect.Height, Color.White, Alignment.Max, Alignment.Max, true);
  
            // ** Create Trigger Window
            hudTrigger.CreateWindow("CreateTrigger", hudTrigger.Rect.Width, hudTrigger.Rect.Height, 20, Alignment.Min, Alignment.Min);
            hudTrigger["CreateTrigger"].IsVisible = false;
            // Background
            hudTrigger["CreateTrigger"].CreateImageField("Background", aryEffects[EFFECT_BASIC], aryTextures[MENU_LIGHT_GRAY],
                hudTrigger["CreateTrigger"].WndRect.Width, hudTrigger["CreateTrigger"].WndRect.Height, Color.White, Alignment.None, Alignment.None, false);
            // Title
            hudTrigger["CreateTrigger"].CreateTextField("Title", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL], "Create Trigger",
                Color.WhiteSmoke, Alignment.Center, Alignment.Min, false);
            // Trigger Type
            hudTrigger["CreateTrigger"].CreateTextField("TypeTitle", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL], "Trigger Type",
                Color.WhiteSmoke, Alignment.Center, Alignment.OneFourth, false);
            // Command Type
            hudTrigger["CreateTrigger"].CreateImageField("Command", aryEffects[EFFECT_BASIC], aryTextures[MENU_COMMAND], iconRect.Width,
                iconRect.Height, Color.White, Alignment.OneFourth, Alignment.Center, true);
            // Proximity Type
            hudTrigger["CreateTrigger"].CreateImageField("Proximity", aryEffects[EFFECT_BASIC], aryTextures[MENU_PROXIMITY], iconRect.Width,
                iconRect.Height, Color.Gray, Alignment.Center, Alignment.Center, true);
            // Timed Type
            hudTrigger["CreateTrigger"].CreateImageField("Timed", aryEffects[EFFECT_BASIC], aryTextures[MENU_CONTINUOUS], iconRect.Width,
                iconRect.Height, Color.Gray, Alignment.ThreeFourths, Alignment.Center, true);
            // Ok
            hudTrigger["CreateTrigger"].CreateCustomField("Ok", aryEffects[EFFECT_BASIC], aryTextures[MENU_DARK_GRAY], buttonRect.Width,
                buttonRect.Height, Color.White, aryFonts[FONTS_SMALL], "Ok", Color.White, Alignment.OneFourth, Alignment.Max, Alignment.Center, Alignment.Center, true);
            // Cancel
            hudTrigger["CreateTrigger"].CreateCustomField("Cancel", aryEffects[EFFECT_BASIC], aryTextures[MENU_DARK_GRAY], buttonRect.Width,
                buttonRect.Height, Color.White, aryFonts[FONTS_SMALL], "Cancel", Color.White, Alignment.ThreeFourths, Alignment.Max, Alignment.Center, Alignment.Center, true);
            #endregion
        }

        private void LoadMap(string fileName)
        {
            if (storageDevice.IsConnected)
            {
                IAsyncResult syncResult = storageDevice.BeginOpenContainer("Maps", null, null);
                // Wait for sync
                syncResult.AsyncWaitHandle.WaitOne();
                StorageContainer storageContainer = storageDevice.EndOpenContainer(syncResult);

                if (storageContainer.FileExists(fileName))
                {
                    // Load map
                    Stream fileStream = storageContainer.OpenFile(fileName, FileMode.Open);
                    MapData newLoadData = IntermediateSerializer.Deserialize<MapData>(XmlReader.Create(fileStream), fileName);

                    // Create map
                    mainMap.LoadMap(newLoadData, aryEffects[EFFECT_SECTOR_BASIC]);

                    // Close
                    fileStream.Close();
                    storageContainer.Dispose();
                    // Complete
                    UpdateAnimationView();
                    UpdateTriggerView();
                    UpdateMenuGraphics();
                    arySounds[SND_DING].Play();
                    gameState = GameState.Normal;
                }
            }
        }

        private void ProcessInput(int mSeconds)
        {
            KeyboardState currentKey = Keyboard.GetState();
            MouseState currentMouse = Mouse.GetState();
            
            switch (gameState)
            {
                case GameState.Normal:
                    // Start Simulation - F1
                    if ((baseKey.IsKeyDown(Keys.F1)) && (currentKey.IsKeyUp(Keys.F1)))
                    { StartSimulation(); }

                    // Load Map - F5
                    if ((baseKey.IsKeyDown(Keys.F5)) && (currentKey.IsKeyUp(Keys.F5)))
                    {
                        hudMapManager["File"].ModifyField("Title", "Load");
                        UpdateFileList();
                        hudMapManager["File"].IsVisible = true;
                        menuState = MenuState.Load;
                    }

                    // Save Map - F8
                    if ((baseKey.IsKeyDown(Keys.F8)) && (currentKey.IsKeyUp(Keys.F8)))
                    { SaveMap(); }

                    // Quick Guide - F12
                    if ((baseKey.IsKeyDown(Keys.F12)) && (currentKey.IsKeyUp(Keys.F12)))
                    { hudMapManager["QuickGuide"].IsVisible = !hudMapManager["QuickGuide"].IsVisible; }

                    #region CAMERA MOVEMENT
                    Player moveCamera;

                    if (menuState == MenuState.Normal) { moveCamera = camera; }
                    else { moveCamera = previewCamera; }

                    // Hold shift to fly
                    if ((baseKey.IsKeyUp(Keys.LeftShift) && baseKey.IsKeyUp(Keys.RightShift))
                        && (currentKey.IsKeyDown(Keys.LeftShift) || currentKey.IsKeyDown(Keys.RightShift)))
                    { moveCamera.MovementType = MoveType.Fly; }
                    // else float
                    else if ((currentKey.IsKeyUp(Keys.LeftShift) && currentKey.IsKeyUp(Keys.RightShift))
                        && (baseKey.IsKeyDown(Keys.LeftShift) || baseKey.IsKeyDown(Keys.RightShift)))
                    { moveCamera.MovementType = MoveType.Float; }

                    Vector3 deltaCamera = Vector3.Zero;

                    // W - Camera Forward
                    if (currentKey.IsKeyDown(Keys.W))
                    { moveCamera.Stride(1); }

                    // S - Camera Backward
                    if (currentKey.IsKeyDown(Keys.S))
                    { moveCamera.Stride(-1); }

                    // A - Camera Left
                    if (currentKey.IsKeyDown(Keys.A))
                    { moveCamera.Strafe(1); }

                    // D - Camera Right
                    if (currentKey.IsKeyDown(Keys.D))
                    { moveCamera.Strafe(-1); }

                    // Up - Camera Up
                    if (currentKey.IsKeyDown(Keys.Up))
                    { moveCamera.Fly(1); }

                    // Down - Camera Down
                    if (currentKey.IsKeyDown(Keys.Down))
                    { moveCamera.Fly(-1); }

                    // Left - Look Left
                    if (currentKey.IsKeyDown(Keys.Left))
                    { moveCamera.Turn(1); }

                    // Right - Look Right
                    if (currentKey.IsKeyDown(Keys.Right))
                    { moveCamera.Turn(-1); }
                    #endregion

                    if (lstSelected.Count > 0)
                    {
                        #region NUMPAD HOT KEYS
                        // ** Hold Space - Single Operations
                        // ** Hold Alt - Scale / Reverse Rotate

                        if (vSnap) { scaleSpeed = .25f; shiftSpeed = GRID_MAJOR; rotateSpeed = DEFAULT_ROT_SPEED; }
                        else { scaleSpeed = GRID_MINOR; shiftSpeed = GRID_MINOR; rotateSpeed = DEFAULT_ROT_SPEED / 100; }

                        // X - NumPad 6
                        if (((currentKey.IsKeyDown(Keys.NumPad6)) && (!currentKey.IsKeyDown(Keys.Space)))
                            || ((currentKey.IsKeyDown(Keys.Space)) && (baseKey.IsKeyDown(Keys.NumPad6)) && (currentKey.IsKeyUp(Keys.NumPad6))))
                        {
                            // + Alt - Scale
                            if (currentKey.IsKeyDown(Keys.LeftAlt) || currentKey.IsKeyDown(Keys.RightAlt))
                            { mainMap[currentSector].ModifyObject(scaleSpeed, 0, 0, lstSelected.ToArray()); }
                            // + R - Rotate
                            else if (currentKey.IsKeyDown(Keys.R))
                            { mainMap[currentSector].ModifyObject(Matrix.CreateFromAxisAngle(Vector3.UnitX, rotateSpeed), lstSelected.ToArray()); }
                            else
                            { mainMap[currentSector].ModifyObject(Vector3.UnitX * shiftSpeed, lstSelected.ToArray()); }
                        }

                        // -X - NumPad 4
                        if (((currentKey.IsKeyDown(Keys.NumPad4)) && (!currentKey.IsKeyDown(Keys.Space)))
                            || ((currentKey.IsKeyDown(Keys.Space)) && (baseKey.IsKeyDown(Keys.NumPad4)) && (currentKey.IsKeyUp(Keys.NumPad4))))
                        {
                            // + Alt - Scale
                            if (currentKey.IsKeyDown(Keys.LeftAlt) || currentKey.IsKeyDown(Keys.RightAlt))
                            { mainMap[currentSector].ModifyObject(-scaleSpeed, 0, 0, lstSelected.ToArray()); }
                            // + R - Rotate
                            else if (currentKey.IsKeyDown(Keys.R))
                            { mainMap[currentSector].ModifyObject(Matrix.CreateFromAxisAngle(Vector3.UnitX, -rotateSpeed), lstSelected.ToArray()); }
                            else
                            { mainMap[currentSector].ModifyObject(-Vector3.UnitX * shiftSpeed, lstSelected.ToArray()); }
                        }

                        // Y - NumPad 8
                        if (((currentKey.IsKeyDown(Keys.NumPad8)) && (!currentKey.IsKeyDown(Keys.Space)))
                            || ((currentKey.IsKeyDown(Keys.Space)) && (baseKey.IsKeyDown(Keys.NumPad8)) && (currentKey.IsKeyUp(Keys.NumPad8))))
                        {
                            // + Alt - Scale
                            if (currentKey.IsKeyDown(Keys.LeftAlt) || currentKey.IsKeyDown(Keys.RightAlt))
                            { mainMap[currentSector].ModifyObject(0, scaleSpeed, 0, lstSelected.ToArray()); }
                            // + R - Rotate
                            else if (currentKey.IsKeyDown(Keys.R))
                            { mainMap[currentSector].ModifyObject(Matrix.CreateFromAxisAngle(Vector3.UnitY, rotateSpeed), lstSelected.ToArray()); }
                            else
                            { mainMap[currentSector].ModifyObject(Vector3.UnitY * shiftSpeed, lstSelected.ToArray()); }
                        }

                        // -Y - NumPad 2
                        if (((currentKey.IsKeyDown(Keys.NumPad2)) && (!currentKey.IsKeyDown(Keys.Space)))
                            || ((currentKey.IsKeyDown(Keys.Space)) && (baseKey.IsKeyDown(Keys.NumPad2)) && (currentKey.IsKeyUp(Keys.NumPad2))))
                        {
                            // + Alt - Scale
                            if (currentKey.IsKeyDown(Keys.LeftAlt) || currentKey.IsKeyDown(Keys.RightAlt))
                            { mainMap[currentSector].ModifyObject(0, -scaleSpeed, 0, lstSelected.ToArray()); }
                            // + R - Rotate
                            else if (currentKey.IsKeyDown(Keys.R))
                            { mainMap[currentSector].ModifyObject(Matrix.CreateFromAxisAngle(Vector3.UnitY, -rotateSpeed), lstSelected.ToArray()); }
                            else
                            { mainMap[currentSector].ModifyObject(-Vector3.UnitY * shiftSpeed, lstSelected.ToArray()); }
                        }

                        // Z - NumPad 9
                        if (((currentKey.IsKeyDown(Keys.NumPad9)) && (!currentKey.IsKeyDown(Keys.Space)))
                            || ((currentKey.IsKeyDown(Keys.Space)) && (baseKey.IsKeyDown(Keys.NumPad9)) && (currentKey.IsKeyUp(Keys.NumPad9))))
                        {
                            // + Alt - Scale
                            if (currentKey.IsKeyDown(Keys.LeftAlt) || currentKey.IsKeyDown(Keys.RightAlt))
                            { mainMap[currentSector].ModifyObject(0, 0, scaleSpeed, lstSelected.ToArray()); }
                            // + R - Rotate
                            else if (currentKey.IsKeyDown(Keys.R))
                            { mainMap[currentSector].ModifyObject(Matrix.CreateFromAxisAngle(Vector3.UnitZ, rotateSpeed), lstSelected.ToArray()); }
                            else
                            { mainMap[currentSector].ModifyObject(Vector3.UnitZ * shiftSpeed, lstSelected.ToArray()); }
                        }

                        // -Z - NumPad 7
                        if (((currentKey.IsKeyDown(Keys.NumPad7)) && (!currentKey.IsKeyDown(Keys.Space)))
                            || ((currentKey.IsKeyDown(Keys.Space)) && (baseKey.IsKeyDown(Keys.NumPad7)) && (currentKey.IsKeyUp(Keys.NumPad7))))
                        {
                            // + Alt - Scale
                            if (currentKey.IsKeyDown(Keys.LeftAlt) || currentKey.IsKeyDown(Keys.RightAlt))
                            { mainMap[currentSector].ModifyObject(0, 0, -scaleSpeed, lstSelected.ToArray()); }
                            // + R - Rotate
                            else if (currentKey.IsKeyDown(Keys.R))
                            { mainMap[currentSector].ModifyObject(Matrix.CreateFromAxisAngle(Vector3.UnitZ, -rotateSpeed), lstSelected.ToArray()); }
                            else
                            { mainMap[currentSector].ModifyObject(-Vector3.UnitZ * shiftSpeed, lstSelected.ToArray()); }
                        }
                        #endregion

                        #region GENERAL EDIT
                        // + Increase
                        if ((baseKey.IsKeyDown(Keys.OemPlus)) && (currentKey.IsKeyUp(Keys.OemPlus)))
                        {
                            if (currentKey.IsKeyDown(Keys.LeftAlt) || currentKey.IsKeyDown(Keys.RightAlt))
                            { mainMap[currentSector].ModifyObject(scaleSpeed, true, lstSelected.ToArray()); }
                            else { mainMap[currentSector].ModifyObject(scaleSpeed, false, lstSelected.ToArray()); }
                        }

                        // - Decrease
                        if ((baseKey.IsKeyDown(Keys.OemMinus)) && (currentKey.IsKeyUp(Keys.OemMinus)))
                        {
                            if (currentKey.IsKeyDown(Keys.LeftAlt) || currentKey.IsKeyDown(Keys.RightAlt))
                            { mainMap[currentSector].ModifyObject(-scaleSpeed, true, lstSelected.ToArray()); }
                            else { mainMap[currentSector].ModifyObject(-scaleSpeed, false, lstSelected.ToArray()); }
                        }

                        // Delete - Delete
                        if ((baseKey.IsKeyDown(Keys.Delete)) && (currentKey.IsKeyUp(Keys.Delete)))
                        {
                            // Preserve animatinos and frames
                            List<MapEntity> lstPreserve = new List<MapEntity>();
                            bool preserving = true;
                            while (preserving)
                            {
                                MapEntity animPreserve = IsSelected(ObjectType.Animation);
                                if (animPreserve == null)
                                {
                                    MapEntity framePreserve = IsSelected(ObjectType.Frame);
                                    if (framePreserve == null) { preserving = false; }
                                    else { lstPreserve.Add(framePreserve); RemoveSelected(framePreserve); }
                                }
                                else { lstPreserve.Add(animPreserve); RemoveSelected(animPreserve); }
                            }
                            mainMap[currentSector].DeleteObject(lstSelected.ToArray());
                            ClearSelected();
                            AddSelected(lstPreserve.ToArray());
                        }

                        // Paste from selected - CTRL + V
                        if ((lstSelected.Count > 0) && (currentKey.IsKeyDown(Keys.LeftControl) || currentKey.IsKeyDown(Keys.RightControl))
                            && (baseKey.IsKeyUp(Keys.V) && currentKey.IsKeyDown(Keys.V)))
                        {
                            MapEntity[] newSelected = mainMap[currentSector].AddObject(lstSelected.ToArray());
                            ClearSelected();
                            AddSelected(newSelected);
                        }
                        #endregion
                    }
                    
                    #region LEFT CLICK
                    if ((baseMouse.LeftButton == XnaButtonState.Pressed) && (currentMouse.LeftButton == XnaButtonState.Released))
                    {
                        Rectangle mouseRect = new Rectangle((int)(currentMouse.X), (int)(currentMouse.Y), 1, 1);

                        switch (menuState)
                        {
                            #region NORMAL
                            case MenuState.Normal:
                                #region MAP MANAGER HUD
                                if (mouseRect.Intersects(hudMapManager.Rect))
                                {
                                    // Main window
                                    if (mouseRect.Intersects(hudMapManager["Main"].WndRect))
                                    {
                                        currentButtonName = hudMapManager["Main"].Click(mouseRect);
                                        if (currentButtonName != null)
                                        {
                                            switch (currentButtonName)
                                            {
                                                case "Load":
                                                    hudMapManager["File"].ModifyField("Title", "Load");
                                                    UpdateFileList();
                                                    hudMapManager["File"].IsVisible = true;
                                                    menuState = MenuState.Load; 
                                                    break;
                                                case "Save":
                                                    SaveMap();
                                                    break;
                                                case "Export":
                                                    ExportMap();
                                                    break;
                                                case "About":
                                                    hudMapManager["About"].IsVisible = !hudMapManager["About"].IsVisible;
                                                    break;
                                                case "Exit":
                                                    ProcessMessage("Are you sure you want to quit?", ExitNatur);
                                                    break;
                                                case "Help":
                                                    hudMapManager["Guide"].IsVisible = !hudMapManager["Guide"].IsVisible;
                                                    break;
                                            }
                                        }
                                    }
                                    // else if Sectors window
                                    else if (mouseRect.Intersects(hudMapManager["Sectors"].WndRect))
                                    {
                                        currentButtonName = hudMapManager["Sectors"].Click(mouseRect);
                                        if (currentButtonName != null)
                                        {
                                            ClearSelected();
                                            switch (currentButtonName)
                                            {
                                                case "NewSector":
                                                    currentSector = mainMap.AddSector(0, aryEffects[EFFECT_SECTOR_BASIC].Clone());
                                                    hudMapManager["Sectors"].ModifyField("Current", currentSector.ToString());
                                                    break;
                                                case "IsVisible":
                                                    mainMap[currentSector].IsVisible = !mainMap[currentSector].IsVisible;
                                                    break;
                                                case "Previous":
                                                    if (currentSector > 0) { currentSector--; }
                                                    hudMapManager["Sectors"].ModifyField("Current", currentSector.ToString());
                                                    UpdateAnimationView();
                                                    UpdateTriggerView();
                                                    UpdateMenuGraphics();
                                                    break;
                                                case "Next":
                                                    if (currentSector < mainMap.SectorCount - 1) { currentSector++; }
                                                    hudMapManager["Sectors"].ModifyField("Current", currentSector.ToString());
                                                    UpdateAnimationView();
                                                    UpdateTriggerView();
                                                    UpdateMenuGraphics();
                                                    break;
                                            }
                                            // Update sector stats
                                            UpdateSectorView();
                                        }
                                    }
                                    // else Simulation Window
                                    else if (mouseRect.Intersects(hudMapManager["Simulation"].WndRect))
                                    {
                                        currentButtonName = hudMapManager["Simulation"].Click(mouseRect);
                                        if (currentButtonName != null)
                                        {
                                            ClearSelected();
                                            switch (currentButtonName)
                                            {
                                                case "Start":
                                                    StartSimulation();
                                                    break;
                                            }
                                        }
                                    }
                                    // else Object info
                                    else if ((mouseRect.Intersects(hudMapManager["ObjectInfo"].WndRect)) && (lstSelected.Count > 0))
                                    {
                                        MapEntity lastSelected = lstSelected[lstSelected.Count - 1];
                                        currentButtonName = hudMapManager["ObjectInfo"].Click(mouseRect);
                                        switch (currentButtonName)
                                        {
                                            // ** For ANIMATIONS
                                            case "Forward":
                                                ((Animation)lastSelected).PlayMode = PlayMode.Forward;
                                                break;
                                            case "Backward":
                                                ((Animation)lastSelected).PlayMode = PlayMode.Backward;
                                                break;
                                            case "Repeat":
                                                ((Animation)lastSelected).Repeat = !((Animation)lastSelected).Repeat;
                                                break;
                                            // ** For BOUNDS
                                            case "LessenE":
                                                ((Bound)lastSelected).Elasticity -= .05f;
                                                if (((Bound)lastSelected).Elasticity < .05f)
                                                { ((Bound)lastSelected).Elasticity = .05f; }
                                                break;
                                            case "IncreaseE":
                                                ((Bound)lastSelected).Elasticity += .05f;
                                                break;
                                            case "LessenF":
                                                ((Bound)lastSelected).Friction = (float)Math.Floor((((Bound)lstSelected[0]).Friction / 2) * 1000) / 1000;
                                                if (((Bound)lastSelected).Friction < .001f)
                                                { ((Bound)lastSelected).Friction = .001f; }
                                                break;
                                            case "IncreaseF":
                                                ((Bound)lastSelected).Friction = (float)Math.Floor((((Bound)lstSelected[0]).Friction * 2) * 1000) / 1000;
                                                break;
                                            case "IsLadder":
                                                ((Bound)lastSelected).IsLadder = !((Bound)lastSelected).IsLadder;
                                                break;
                                            // ** For INTERACTIVE STRUCTURES
                                            case "BakeState":
                                                ((InteractiveStructure)lastSelected).BakeState();
                                                break;
                                            // ** For SPAWNS
                                            case "LessenSpawn":
                                                if (((Spawn)lastSelected).SpawnID > 0)
                                                { ((Spawn)lastSelected).SpawnID--; }
                                                break;
                                            case "IncreaseSpawn":
                                                ((Spawn)lastSelected).SpawnID++;
                                                break;
                                            case "LessenSpawnCount":
                                                if (((Spawn)lastSelected).Count > 0)
                                                { ((Spawn)lastSelected).Count--; }
                                                break;
                                            case "IncreaseSpawnCount":
                                                ((Spawn)lastSelected).Count++;
                                                break;
                                            case "LessenSpawnDelay":
                                                if (((Spawn)lastSelected).Delay > 0)
                                                { ((Spawn)lastSelected).Delay -= .25f; }
                                                break;
                                            case "IncreaseSpawnDelay":
                                                ((Spawn)lastSelected).Delay += .25f;
                                                break;
                                            // ** For TRIGGERS
                                            case "LessenCommand":
                                                if (((CommandTrigger)lastSelected).CommandIndex > 0)
                                                { ((CommandTrigger)lastSelected).CommandIndex--; }
                                                break;
                                            case "LessenDelay":
                                                if (((TimedTrigger)lastSelected).Delay > 0)
                                                { ((TimedTrigger)lastSelected).Delay -= .25f; }
                                                break;
                                            case "LessenOccurrences":
                                                if (((Trigger)lastSelected).Occurences > 0)
                                                { ((Trigger)lastSelected).Occurences--; }
                                                break;
                                            case "IncreaseCommand":
                                                ((CommandTrigger)lastSelected).CommandIndex++;
                                                break;
                                            case "IncreaseDelay":
                                                ((TimedTrigger)lastSelected).Delay += .25f;
                                                break;
                                            case "IncreaseOccurrences":
                                                ((Trigger)lastSelected).Occurences++;
                                                break;
                                            case "LocationFound":
                                                break;
                                            case "CommitLocation":
                                                Location selectedLocation = IsSelected(ObjectType.Location) as Location;
                                                if (selectedLocation != null)
                                                { ((ProximityTrigger)lastSelected).Location = selectedLocation; }
                                                break;
                                            case "CommitTarget":
                                                // Look for targetable object and add - can't target self
                                                for (int i = 0; i < lstSelected.Count - 1; i++)
                                                {
                                                    if (lstSelected[i] is IActivatable)
                                                    { ((Trigger)lastSelected).AddTarget(lstSelected[i]); }
                                                }
                                                break;
                                            case "TargetFound":
                                                break;
                                        }
                                        UpdateObjectProperties();
                                    }
                                    // else check for system click
                                    else if (mouseRect.Intersects(hudMapManager["System"].WndRect))
                                    {
                                        currentButtonName = hudMapManager["System"].Click(mouseRect);
                                        switch (currentButtonName)
                                        {
                                            case "ToggleAnimations":
                                                hudAnimation.IsVisible = !hudAnimation.IsVisible;
                                                // Clear animated related selections if not visible
                                                if (!hudAnimation.IsVisible)
                                                { RemoveSelected(ObjectType.Animation, ObjectType.Frame); }
                                                break;
                                            case "ToggleTrigger":
                                                hudTrigger.IsVisible = !hudTrigger.IsVisible;
                                                break;
                                            case "ToggleVCT":
                                                hudView.IsVisible = !hudView.IsVisible;
                                                hudConstruction.IsVisible = !hudConstruction.IsVisible;
                                                hudTexture.IsVisible = !hudTexture.IsVisible;
                                                break;
                                        }
                                    }
                                    currentButtonName = "Window Hit";
                                }
                                #endregion

                                #region VIEW HUD
                                if ((currentButtonName == null) && (mouseRect.Intersects(hudView.Rect)) && (hudView.IsVisible))
                                {
                                    if (hudView["System"].WndRect.Intersects(mouseRect))
                                    {
                                        hudView["Main"].IsVisible = !hudView["Main"].IsVisible;
                                        SnapHuds(hudMapManager, "Main", hudView, "Main", SnapSide.Bottom);
                                        SnapHuds(hudView, "Main", hudConstruction, "Main", SnapSide.Bottom);
                                        SnapHuds(hudConstruction, "Main", hudTexture, "Main", SnapSide.Bottom);
                                    }
                                    else if ((hudView["Main"].IsVisible) && hudView["Main"].WndRect.Intersects(mouseRect))
                                    {
                                        currentButtonName = hudView["Main"].Click(mouseRect);
                                        switch (currentButtonName)
                                        {
                                            case "Construction":
                                                hudView["Main"].ModifyField(currentLayer.ToString(), Color.Gray);
                                                currentLayer = LayerType.Construction;
                                                hudView["Main"].ModifyField(currentLayer.ToString(), Color.White);
                                                break;
                                            case "Bound":
                                                hudView["Main"].ModifyField(currentLayer.ToString(), Color.Gray);
                                                currentLayer = LayerType.Bound;
                                                hudView["Main"].ModifyField(currentLayer.ToString(), Color.White);
                                                break;
                                            case "Light":
                                                hudView["Main"].ModifyField(currentLayer.ToString(), Color.Gray);
                                                currentLayer = LayerType.Light;
                                                hudView["Main"].ModifyField(currentLayer.ToString(), Color.White);
                                                break;
                                            case "Location":
                                                hudView["Main"].ModifyField(currentLayer.ToString(), Color.Gray);
                                                currentLayer = LayerType.Location;
                                                hudView["Main"].ModifyField(currentLayer.ToString(), Color.White);
                                                break;
                                            case "VisibleConstruction":
                                                showConstruction = !showConstruction;
                                                if (showConstruction)
                                                { hudView["Main"].ModifyField(currentButtonName, Color.White); }
                                                else
                                                { hudView["Main"].ModifyField(currentButtonName, Color.Gray); }
                                                break;
                                            case "VisibleBound":
                                                showBounds = !showBounds;
                                                if (showBounds)
                                                { hudView["Main"].ModifyField(currentButtonName, Color.White); }
                                                else
                                                { hudView["Main"].ModifyField(currentButtonName, Color.Gray); }
                                                break;
                                            case "VisibleLight":
                                                showLights = !showLights;
                                                if (showLights)
                                                { hudView["Main"].ModifyField(currentButtonName, Color.White); }
                                                else
                                                { hudView["Main"].ModifyField(currentButtonName, Color.Gray); }
                                                break;
                                            case "VisibleLocation":
                                                showLocations = !showLocations;
                                                if (showLocations)
                                                { hudView["Main"].ModifyField(currentButtonName, Color.White); }
                                                else
                                                { hudView["Main"].ModifyField(currentButtonName, Color.Gray); }
                                                break;
                                        }
                                    }
                                    currentButtonName = "Window Hit";
                                }
                                #endregion

                                #region CONSTRUCTION HUD
                                if ((currentButtonName == null) && hudConstruction.Rect.Intersects(mouseRect) && (hudConstruction.IsVisible))
                                {
                                    if (hudConstruction["System"].WndRect.Intersects(mouseRect))
                                    {
                                        hudConstruction["Main"].IsVisible = !hudConstruction["Main"].IsVisible;
                                        SnapHuds(hudView, "Main", hudConstruction, "Main", SnapSide.Bottom);
                                        SnapHuds(hudConstruction, "Main", hudTexture, "Main", SnapSide.Bottom);
                                    }
                                    else if ((hudConstruction["Main"].IsVisible) && hudConstruction["Main"].WndRect.Intersects(mouseRect))
                                    {
                                        currentButtonName = hudConstruction["Main"].Click(mouseRect);
                                        // Prepare construction
                                        ClearStructs(true);
                                        
                                        switch (currentButtonName)
                                        {
                                            case "Paint":
                                                mainMap[currentSector].ModifyObject(structTexStart, structTexDimension, lstSelected.ToArray());
                                                break;
                                            case "Pin":
                                                MapEntity newPin = mainMap[currentSector].PinObjects(lstSelected.ToArray());
                                                ClearSelected(ObjectType.Animation);
                                                AddSelected(newPin);
                                                break;
                                            case "Unpin":
                                                mainMap[currentSector].UnpinObjects(lstSelected.ToArray());
                                                ClearSelected(ObjectType.Animation);
                                                break;
                                            case "VertexSnap":
                                                vSnap = !vSnap;
                                                if (vSnap) {
                                                    hudConstruction["Main"].ModifyField("VertexSnap", Color.White);
                                                    //mainMap.GridSize = GRID_MAJOR;
                                                }
                                                else
                                                {
                                                    hudConstruction["Main"].ModifyField("VertexSnap", Color.Gray);
                                                    //mainMap.GridSize = GRID_MINOR;
                                                }
                                                break;
                                            case "Link":
                                                mainMap[currentSector].LinkObjects(lstSelected.ToArray());
                                                break;
                                            case "Box":
                                                if (structBound != BoundType.Null)
                                                { hudConstruction["Main"].ModifyField(structBound.ToString(), Color.Gray); }

                                                if (structBound == BoundType.Box)
                                                { structBound = BoundType.Null; }
                                                else
                                                {
                                                    structBound = BoundType.Box;
                                                    hudConstruction["Main"].ModifyField(structBound.ToString(), Color.White);
                                                }
                                                break;
                                            case "Sphere":
                                                if (structBound != BoundType.Null)
                                                { hudConstruction["Main"].ModifyField(structBound.ToString(), Color.Gray); }

                                                if (structBound == BoundType.Sphere)
                                                { structBound = BoundType.Null; }
                                                else
                                                {
                                                    structBound = BoundType.Sphere;
                                                    hudConstruction["Main"].ModifyField(structBound.ToString(), Color.White);
                                                }
                                                break;
                                            case "AddBound":
                                                ClearSelected(ObjectType.Animation);
                                                if (structBound == BoundType.Box)
                                                {
                                                    AddSelected(mainMap[currentSector].AddBound(structPosition, structForward, structUp,
                                                        structW, structH, structD));
                                                }
                                                else if (structBound == BoundType.Sphere)
                                                { AddSelected(mainMap[currentSector].AddBound(structPosition, (structW + structH + structD) / 3)); }
                                                break;
                                            case "AddLocation":
                                                MapEntity newLocation;
                                                if (structBound == BoundType.Box)
                                                {
                                                    newLocation = mainMap[currentSector].AddLocation(structPosition, structForward,
                                                        structUp, 2 * structW, 2 * structH, 2 * structW);
                                                }
                                                else
                                                { newLocation = mainMap[currentSector].AddLocation(structPosition, structW + structH + structD); }
                                                ClearSelected(ObjectType.Animation);
                                                AddSelected(newLocation);
                                                break;
                                            case "AddSpawn":
                                                ClearSelected(ObjectType.Animation);
                                                AddSelected(mainMap[currentSector].AddSpawn(structPosition, 0, 0, 5));
                                                break;
                                            case "AddRelay":
                                                ClearSelected(ObjectType.Animation);
                                                AddSelected(mainMap[currentSector].AddRelay(structPosition));
                                                break;
                                            case "AddStructure":
                                                ClearCustomVertices();
                                                previewCamera.Position = structPosition - structForward * 2.5f * CAMERA_RADIUS;
                                                previewCamera.Forward = structForward;
                                                previewCamera.Up = structUp;
                                                structInteractive = false;
                                                menuState = MenuState.Create_Structure;
                                                break;
                                            case "AddInteractive":
                                                ProcessMessage("Interactive Structures have been temporarily disabled.", null);
                                                /*
                                                ClearCustomVertices();
                                                previewCamera.Position = structPosition - structForward * 2.5f * CAMERA_RADIUS;
                                                previewCamera.Forward = structForward;
                                                previewCamera.Up = structUp;
                                                structInteractive = true;
                                                menuState = MenuState.Create_Structure;*/
                                                break;
                                            case "AddLight":
                                                MapEntity newLight = mainMap[currentSector].AddLight(structPosition, structForward, structUp, Color.White, DEFAULT_INTENSITY, 0);
                                                ClearSelected(ObjectType.Animation);
                                                AddSelected(newLight);
                                                break;
                                            case "BakeLight":
                                                if (currentKey.IsKeyDown(Keys.LeftAlt) || currentKey.IsKeyDown(Keys.RightAlt))
                                                { mainMap.BakeLights(); }
                                                else
                                                { mainMap[currentSector].BakeLights(); }
                                                break;
                                        }
                                    }
                                    currentButtonName = "Window Hit";
                                }
                                #endregion
                                
                                #region TEXTURE HUD
                                if ((currentButtonName == null) && hudTexture.Rect.Intersects(mouseRect) && (hudTexture.IsVisible))
                                {
                                    if (hudTexture["System"].WndRect.Intersects(mouseRect))
                                    {
                                        hudTexture["Main"].IsVisible = !hudTexture["Main"].IsVisible;
                                        SnapHuds(hudConstruction, "Main", hudTexture, "Main", SnapSide.Bottom);
                                    }
                                    else if ((hudTexture["Main"].IsVisible) && hudTexture["Main"].WndRect.Intersects(mouseRect))
                                    {
                                        currentButtonName = hudTexture["Main"].Click(mouseRect);
                                        switch (currentButtonName)
                                        {
                                            case "ActiveTex": // Next texture
                                                // Next X, with wrap
                                                structTexStart.X += structTexDimension.X;
                                                if (structTexStart.X > 1 - structTexDimension.X)
                                                {
                                                    structTexStart.X = 0;
                                                    // Next Y, with wrap
                                                    structTexStart.Y += structTexDimension.Y;
                                                    if (structTexStart.Y > 1 - structTexDimension.X)
                                                    { structTexStart.Y = 0; }
                                                }
                                                break;
                                            case "TexPreview": // Select texture
                                                structTexStart = new Vector2(
                                                    structTexDimension.X * (float)((mouseRect.X - hudTexture["Main"]["TexPreview"].DrawRect.X) * 8
                                                        / hudTexture["Main"]["TexPreview"].DrawRect.Width),
                                                    structTexDimension.Y * (float)((mouseRect.Y - hudTexture["Main"]["TexPreview"].DrawRect.Y) * 8
                                                        / hudTexture["Main"]["TexPreview"].DrawRect.Height));
                                                break;
                                            case "PreviousPalette":
                                                if (structPalette > 0)
                                                {
                                                    structPalette--;
                                                    aryEffects[EFFECT_SECTOR_BASIC].Parameters["baseTexture"].SetValue(aryTextures[GetPaletteIndex(structPalette)]);
                                                    mainMap.GetSectorEffect(currentSector).Parameters["baseTexture"].SetValue(aryTextures[GetPaletteIndex(structPalette)]);
                                                }
                                                break;
                                            case "NextPalette":
                                                if (structPalette < PALETTE_COUNT - 1)
                                                {
                                                    structPalette++;
                                                    aryEffects[EFFECT_SECTOR_BASIC].Parameters["baseTexture"].SetValue(aryTextures[GetPaletteIndex(structPalette)]);
                                                    mainMap.GetSectorEffect(currentSector).Parameters["baseTexture"].SetValue(aryTextures[GetPaletteIndex(structPalette)]);
                                                }
                                                break;
                                        }
                                    }
                                    currentButtonName = "Window Hit";
                                }
                                #endregion
                                
                                #region TRANSFORMATIONS HUD
                                if ((currentButtonName == null) && hudTransform.Rect.Intersects(mouseRect) && (hudTransform.IsVisible))
                                {
                                    if (hudTransform["System"].WndRect.Intersects(mouseRect))
                                    {
                                        hudTransform["Main"].IsVisible = !hudTransform["Main"].IsVisible;
                                        currentButtonName = "Window Hit";
                                    }
                                    else if ((hudTransform["Main"].IsVisible) && hudTransform["Main"].WndRect.Intersects(mouseRect))
                                    {
                                        currentButtonName = hudTransform["Main"].Click(mouseRect);
                                        switch (currentButtonName)
                                        {
                                            case "IncreaseHeight":
                                                mainMap[currentSector].ModifyObject(0, scaleSpeed, 0, lstSelected.ToArray());
                                                break;
                                            case "DecreaseHeight":
                                                mainMap[currentSector].ModifyObject(0, -scaleSpeed, 0, lstSelected.ToArray());
                                                break;
                                            case "IncreaseWidth":
                                                mainMap[currentSector].ModifyObject(scaleSpeed, 0, 0, lstSelected.ToArray());
                                                break;
                                            case "DecreaseWidth":
                                                mainMap[currentSector].ModifyObject(-scaleSpeed, 0, 0, lstSelected.ToArray());
                                                break;
                                        }
                                        currentButtonName = "Window Hit";
                                    }
                                }
                                #endregion
                                
                                #region ANIMATION HUD
                                if ((currentButtonName == null) && hudAnimation.Rect.Intersects(mouseRect) && (hudAnimation.IsVisible))
                                {
                                    #region ANIMATION CONTROL
                                    if ((hudAnimation["AnimationControl"].IsVisible) && hudAnimation["AnimationControl"].WndRect.Intersects(mouseRect))
                                    {
                                        currentButtonName = hudAnimation["AnimationControl"].Click(mouseRect);
                                        if (currentButtonName != null)
                                        {
                                            switch (currentButtonName)
                                            {
                                                case "NewAnimation":
                                                    RemoveSelected(ObjectType.Animation, ObjectType.Frame);
                                                    AddSelected(mainMap[currentSector].AddAnimation());
                                                    break;
                                                case "DeleteAnimation":
                                                    MapEntity deleteAnim = IsSelected(ObjectType.Animation);
                                                    if (deleteAnim != null)
                                                    {
                                                        mainMap[currentSector].DeleteObject(deleteAnim);
                                                        RemoveSelected(ObjectType.Animation, ObjectType.Frame);
                                                    }
                                                    break;
                                                case "NewFrame":
                                                    Animation animFrame = IsSelected(ObjectType.Animation) as Animation;
                                                    if (animFrame != null)
                                                    {
                                                        animFrame.AddFrame(animFrame.PlayPosition);
                                                        UpdateAnimationView();
                                                    }
                                                    break;
                                                case "DeleteFrame":
                                                    MapEntity animFrameTest = IsSelected(ObjectType.Animation);
                                                    if (animFrameTest != null)
                                                    {
                                                        Animation animFrameHold = animFrameTest as Animation;
                                                        bool deletingFrames = true;
                                                        while (deletingFrames)
                                                        {
                                                            MapEntity frameTest = IsSelected(ObjectType.Frame);
                                                            if (frameTest != null)
                                                            {
                                                                AnimationFrame deleteFrame = frameTest as AnimationFrame;
                                                                float minTime = deleteFrame.TimePosition - .01f;
                                                                float maxTime = deleteFrame.TimePosition + .01f;
                                                                animFrameHold.DeleteRange(minTime, maxTime);
                                                                RemoveSelected(ObjectType.Frame);
                                                            }
                                                            else { deletingFrames = false; }
                                                        }
                                                    }
                                                    break;
                                                case "LinkStructure":
                                                    MapEntity linkTest = IsSelected(ObjectType.Animation);
                                                    if (linkTest != null)
                                                    {
                                                        Animation animHold = linkTest as Animation;
                                                        animHold.AddObject(lstSelected.ToArray());
                                                        UpdateAnimationView();
                                                    }
                                                    break;
                                                case "UnlinkStructure":
                                                    MapEntity unlinkTest = IsSelected(ObjectType.Animation);
                                                    if (unlinkTest != null)
                                                    {
                                                        Animation animHold = unlinkTest as Animation;
                                                        animHold.RemoveObject(lstSelected.ToArray());
                                                    }
                                                    break;
                                                case "ApplyState":
                                                    MapEntity applyTest = IsSelected(ObjectType.Animation);
                                                    if (applyTest != null)
                                                    {
                                                        Animation animHold = applyTest as Animation;
                                                        animHold.BakeState(autoState, lstSelected.ToArray());
                                                    }
                                                    break;
                                                case "AutoState":
                                                    autoState = !autoState;
                                                    if (autoState)
                                                    { hudAnimation["AnimationControl"].ModifyField("AutoState", Color.White); }
                                                    else
                                                    { hudAnimation["AnimationControl"].ModifyField("AutoState", Color.Gray); }
                                                    break;
                                                case "Play":
                                                    MapEntity playTest = IsSelected(ObjectType.Animation);
                                                    if (playTest != null)
                                                    { mainMap[currentSector].ActivateObject(playTest); }
                                                    break;
                                                case "Pause":
                                                    MapEntity pauseTest = IsSelected(ObjectType.Animation);
                                                    if (pauseTest != null)
                                                    { mainMap[currentSector].DeactivateObject(pauseTest); }
                                                    break;
                                                case "Stop":
                                                    Animation stopTest = IsSelected(ObjectType.Animation) as Animation;
                                                    if (stopTest != null)
                                                    {
                                                        mainMap[currentSector].DeactivateObject(stopTest);
                                                        stopTest.Reset();
                                                        mainMap[currentSector].SetAnimation(stopTest.PlayPosition, stopTest);
                                                    }
                                                    break;
                                            }
                                        }
                                    }
                                    #endregion
                                    else if ((hudAnimation["AnimationSelect"].IsVisible) && hudAnimation["AnimationSelect"].WndRect.Intersects(mouseRect))
                                    {
                                        currentButtonName = hudAnimation["AnimationSelect"].Click(mouseRect);
                                        if (currentButtonName != null)
                                        {
                                            int animationIndex = Int32.Parse(currentButtonName);
                                            RemoveSelected(ObjectType.Animation, ObjectType.Frame);
                                            AddSelected(mainMap[currentSector].Animations[animationIndex]);
                                        }
                                    }
                                    #region FRAME/STATE SELECT AND CONTROLS
                                    else if ((hudAnimation["StateSelect"].IsVisible) && hudAnimation["StateSelect"].WndRect.Intersects(mouseRect))
                                    {
                                        // With CTRL - Select Multiple
                                        if (!(currentKey.IsKeyDown(Keys.LeftControl) || (currentKey.IsKeyDown(Keys.RightControl))))
                                        { ClearSelected(ObjectType.Animation); }

                                        currentButtonName = hudAnimation["StateSelect"].Click(mouseRect);
                                        if (currentButtonName != null)
                                        {
                                            Animation animHold = IsSelected(ObjectType.Animation) as Animation;
                                            if (animHold != null)
                                            {
                                                int newStateSelect = -1;
                                                int newFrameSelect = -1;
                                                int toColon = currentButtonName.IndexOf(":");
                                                // Convert into indices
                                                currentButtonName = currentButtonName.Remove(0, 1);
                                                newFrameSelect = Int32.Parse(currentButtonName.Substring(0, toColon - 1));
                                                currentButtonName = currentButtonName.Remove(0, toColon);
                                                newStateSelect = Int32.Parse(currentButtonName);
                                                // Add selected
                                                AnimationFrame frameHold = animHold.Frames[newFrameSelect];
                                                AddSelected(animHold.AnimatedObjects[newStateSelect], frameHold);
                                                mainMap[currentSector].SetAnimationState(frameHold.TimePosition, lstSelected.ToArray());
                                            }
                                            else
                                            { throw (new Exception("No Animation selected in State Select")); }
                                        }
                                    }
                                    else if ((hudAnimation["FrameSelect"].IsVisible) && hudAnimation["FrameSelect"].WndRect.Intersects(mouseRect))
                                    {
                                        RemoveSelected(ObjectType.Frame);
                                        currentButtonName = hudAnimation["FrameSelect"].Click(mouseRect);
                                        Animation animHold = IsSelected(ObjectType.Animation) as Animation;
                                        if (animHold != null)
                                        {
                                            if (currentButtonName != null)
                                            {
                                                currentButtonName = currentButtonName.Remove(0, 1);
                                                int newFrameIndex = Int32.Parse(currentButtonName);
                                                AnimationFrame frameHold = animHold.Frames[newFrameIndex];
                                                // Set all states and add frame - Updates view
                                                mainMap[currentSector].SetAnimation(frameHold.TimePosition, animHold);
                                                AddSelected(frameHold);
                                            }
                                            else
                                            {
                                                float newTime = ((mouseRect.X - hudAnimation["FrameSelect"].WndRect.X) * animHold.Duration) / hudAnimation["FrameSelect"].WndRect.Width;
                                                mainMap[currentSector].SetAnimation(newTime, animHold);
                                                UpdateAnimationView();
                                            }
                                        }
                                    }
                                    else if ((hudAnimation["TimeControl"].IsVisible) && hudAnimation["TimeControl"].WndRect.Intersects(mouseRect))
                                    {
                                        currentButtonName = hudAnimation["TimeControl"].Click(mouseRect);
                                        if (currentButtonName != null)
                                        {
                                            MapEntity animTest = IsSelected(ObjectType.Animation);
                                            if (animTest != null)
                                            {
                                                float dTime = .25f;
                                                // Hold ALT - Change Time by seconds
                                                if (currentKey.IsKeyDown(Keys.LeftAlt) || currentKey.IsKeyDown(Keys.RightAlt))
                                                { dTime = 1; }
                                                Animation animHold = animTest as Animation;
                                                switch (currentButtonName)
                                                {
                                                    case "LessenTime": // Lessen Time
                                                        if (animHold.Duration - dTime > 0)
                                                        { animHold.Duration -= dTime; }
                                                        break;
                                                    case "IncreaseTime": // Increase Time
                                                        animHold.Duration += dTime;
                                                        break;
                                                }
                                                UpdateAnimationView();
                                            }
                                        }
                                    }
                                    #endregion
                                    currentButtonName = "Window Hit";
                                }
                                #endregion

                                #region TRIGGER HUD
                                if ((currentButtonName == null) && hudTrigger.Rect.Intersects(mouseRect) && (hudTrigger.IsVisible))
                                {
                                    if ((hudTrigger["TriggerSelect"].IsVisible) && hudTrigger["TriggerSelect"].WndRect.Intersects(mouseRect))
                                    {
                                        currentButtonName = hudTrigger["TriggerSelect"].Click(mouseRect);
                                        if (currentButtonName != null)
                                        {
                                            int triggerIndex = Int32.Parse(currentButtonName);
                                            RemoveSelected(ObjectType.Trigger);
                                            AddSelected(mainMap[currentSector].Triggers[triggerIndex]);
                                        }
                                        currentButtonName = "Window Hit";
                                    }
                                    else if ((hudTrigger["Main"].IsVisible) && hudTrigger["Main"].WndRect.Intersects(mouseRect))
                                    {
                                        currentButtonName = hudTrigger["Main"].Click(mouseRect);
                                        switch (currentButtonName)
                                        {
                                            case "NewTrigger":
                                                hudTrigger["CreateTrigger"].IsVisible = true;
                                                menuState = MenuState.TriggerCreate;
                                                break;
                                            case "DeleteTrigger":
                                                MapEntity selectedTrigger = IsSelected(ObjectType.Trigger);
                                                if (selectedTrigger != null) { mainMap[currentSector].DeleteObject(selectedTrigger); }
                                                UpdateTriggerView();
                                                break;
                                        }
                                        currentButtonName = "Window Hit";
                                    }
                                }
                                #endregion

                                // if map click
                                if (currentButtonName == null)
                                {
                                    if (currentSector != -1)
                                    {
                                        bool overridePin = false;
                                        bool collectPin = false;

                                        // Alt - Override pin select ** Alt + B - Collect pins
                                        if (currentKey.IsKeyDown(Keys.LeftAlt) || currentKey.IsKeyDown(Keys.RightAlt))
                                        {
                                            if (currentKey.IsKeyUp(Keys.B))
                                            { overridePin = true; }
                                            else { collectPin = true; }
                                        }

                                        Vector3 rayMin = GraphicsDevice.Viewport.Unproject(new Vector3(currentMouse.X, currentMouse.Y, 0), projMat, viewMat, worldMat);
                                        Vector3 rayMax = GraphicsDevice.Viewport.Unproject(new Vector3(currentMouse.X, currentMouse.Y, 1), projMat, viewMat, worldMat);

                                        // Find 
                                        MapEntity newSelected = mainMap[currentSector].SelectObject(currentLayer, new Ray(rayMin, Vector3.Normalize(rayMax - rayMin)), overridePin);
                                        if (newSelected != null)
                                        {
                                            // With CTRL - Select multiple
                                            if (!(currentKey.IsKeyDown(Keys.LeftControl) || currentKey.IsKeyDown(Keys.RightControl)))
                                            { ClearSelected(ObjectType.Animation, ObjectType.Frame); }

                                            if ((newSelected is IPin) && (collectPin))
                                            { AddSelected(((IPin)newSelected).Pinned); }
                                            else { AddSelected(newSelected); }
                                        }
                                        else
                                        { ClearSelected(); }
                                    }
                                }
                                break;
                            #endregion

                            #region LOAD
                            case MenuState.Load:
                                currentButtonName = hudMapManager["File"].Click(mouseRect);
                                if (currentButtonName == "Ok")
                                {
                                    hudMapManager["File"].IsVisible = false;
                                    LoadMap(currentFile);
                                    menuState = MenuState.Normal;
                                }
                                else if (currentButtonName == "Cancel")
                                {
                                    hudMapManager["File"].IsVisible = false;
                                    menuState = MenuState.Normal;
                                }
                                else if (currentButtonName != null)
                                {
                                    currentFile = currentButtonName;
                                    UpdateFileList();
                                    hudMapManager["File"].ModifyField(currentFile, Color.BlueViolet);
                                }
                                break;
                            #endregion

                            #region MESSAGE
                            case MenuState.Message:
                            currentButtonName = hudMapManager["Message"].Click(mouseRect);
                            if (currentButtonName == "Ok")
                            {
                                hudMapManager["Message"].IsVisible = false;
                                if (callbackConfirm != null)
                                { callbackConfirm(); }
                                menuState = MenuState.Normal;
                            }
                            else if (currentButtonName == "Cancel")
                            {
                                hudMapManager["Message"].IsVisible = false;
                                menuState = MenuState.Normal;
                            }
                            break;
                            #endregion

                            #region CREATE STRUCTURE
                            case MenuState.Create_Structure:
                                #region BASE TYPE
                                if (hudCreateStructure["BaseType"].WndRect.Intersects(mouseRect))
                                {
                                    currentButtonName = hudCreateStructure["BaseType"].Click(mouseRect);
                                    if ((currentButtonName != null) && (currentButtonName != structBase.ToString()))
                                    {
                                        hudCreateStructure["BaseType"].ModifyField(structBase.ToString(), Color.Gray);
                                        switch (currentButtonName)
                                        {
                                            case "Cone":
                                                structBase = BaseType.Cone;
                                                break;
                                            case "Cube":
                                                structBase = BaseType.Cube;
                                                break;
                                            case "Cylinder":
                                                structBase = BaseType.Cylinder;
                                                break;
                                            case "FuturePillar":
                                                structBase = BaseType.FuturePillar;
                                                break;
                                            case "Generator":
                                                structBase = BaseType.Generator;
                                                break;
                                            case "GrateWindow":
                                                structBase = BaseType.GrateWindow;
                                                break;
                                            case "Plane":
                                                structBase = BaseType.Plane;
                                                break;
                                            case "PowerPlant1":
                                                structBase = BaseType.PowerPlant1;
                                                break;
                                            case "Sphere":
                                                structBase = BaseType.Sphere;
                                                break;
                                            case "Triangle":
                                                structBase = BaseType.Triangle;
                                                break;
                                            case "Wall":
                                                structBase = BaseType.Wall;
                                                break;
                                        }
                                        hudCreateStructure["BaseType"].ModifyField(structBase.ToString(), Color.White);
                                        ClearStructs(false);
                                        ClearCustomVertices();
                                    }
                                }
                                #endregion

                                #region AFFECTED AXIS
                                if (hudCreateStructure["Axis"].WndRect.Intersects(mouseRect))
                                {
                                    currentButtonName = hudCreateStructure["Axis"].Click(mouseRect);
                                    if (currentButtonName != null)
                                    {
                                        switch (currentButtonName)
                                        {
                                            case "X":
                                                affectX = !affectX;
                                                if (affectX) { hudCreateStructure["Axis"].ModifyField("X", Color.Black); }
                                                else { hudCreateStructure["Axis"].ModifyField("X", Color.Silver); }
                                                break;
                                            case "Y":
                                                affectY = !affectY;
                                                if (affectY) { hudCreateStructure["Axis"].ModifyField("Y", Color.Black); }
                                                else { hudCreateStructure["Axis"].ModifyField("Y", Color.Silver); }
                                                break;
                                            case "Z":
                                                affectZ = !affectZ;
                                                if (affectZ) { hudCreateStructure["Axis"].ModifyField("Z", Color.Black); }
                                                else { hudCreateStructure["Axis"].ModifyField("Z", Color.Silver); }
                                                break;
                                        }
                                        ClearStructs(false);
                                        ClearCustomVertices();
                                    }
                                }
                                #endregion

                                #region PROTRUSION
                                if (hudCreateStructure["Protrusion"].WndRect.Intersects(mouseRect))
                                {
                                    currentButtonName = hudCreateStructure["Protrusion"].Click(mouseRect);
                                    if (currentButtonName != null)
                                    {
                                        switch (currentButtonName)
                                        {
                                            case "Concave":
                                                structProtrusion -= 5;
                                                if (structProtrusion < 0) { structProtrusion = 0; }
                                                break;
                                            case "Convex":
                                                structProtrusion += 5;
                                                if (structProtrusion > 100) { structProtrusion = 100; }
                                                break;
                                        }
                                        hudCreateStructure["Protrusion"].ModifyField("Amount", structProtrusion.ToString());
                                        hudCreateStructure["Protrusion"].ModifyField("Ticker", new Vector2(
                                            hudCreateStructure["Protrusion"]["Line"].DrawRect.X
                                            + (structProtrusion / 100) * hudCreateStructure["Protrusion"]["Line"].DrawRect.Width,
                                            hudCreateStructure["Protrusion"]["Ticker"].DrawRect.Y));
                                        ClearStructs(false);
                                        ClearCustomVertices();
                                    }
                                }
                                #endregion

                                #region ROUGHNESS
                                if (hudCreateStructure["Roughness"].WndRect.Intersects(mouseRect))
                                {
                                    currentButtonName = hudCreateStructure["Roughness"].Click(mouseRect);
                                    if (currentButtonName != null)
                                    {
                                        switch (currentButtonName)
                                        {
                                            case "Smooth":
                                                structRoughness -= 5;
                                                if (structRoughness < 0) { structRoughness = 0; }
                                                break;
                                            case "Rough":
                                                structRoughness += 5;
                                                if (structRoughness > 100) { structRoughness = 100; }
                                                break;
                                        }
                                        hudCreateStructure["Roughness"].ModifyField("Amount", structRoughness.ToString());
                                        hudCreateStructure["Roughness"].ModifyField("Ticker", new Vector2(
                                            hudCreateStructure["Roughness"]["Line"].DrawRect.X
                                            + (structRoughness / 100) * hudCreateStructure["Roughness"]["Line"].DrawRect.Width,
                                            hudCreateStructure["Roughness"]["Ticker"].DrawRect.Y));
                                        ClearStructs(false);
                                        ClearCustomVertices();
                                    }
                                }
                                #endregion

                                #region CONFIRMATION
                                if (hudCreateStructure["Confirmation"].WndRect.Intersects(mouseRect))
                                {
                                    currentButtonName = hudCreateStructure["Confirmation"].Click(mouseRect);
                                    if (currentButtonName != null)
                                    {
                                        switch (currentButtonName)
                                        {
                                            case "Ok":
                                                List<MapEntity> holdSelected = new List<MapEntity>(1);
                                                ClearSelected(ObjectType.Animation);

                                                if (structInteractive)
                                                {
                                                    if (structBound == BoundType.Sphere)
                                                    {
                                                        holdSelected.Add(mainMap[currentSector].AddInteractiveStructure(aryCustomVerts, aryCustomInds,
                                                            structPosition, structForward, structUp, structTexStart, structTexDimension, structW, structH, structD, BoundType.Sphere));
                                                    }
                                                    else
                                                    {
                                                        holdSelected.Add(mainMap[currentSector].AddInteractiveStructure(aryCustomVerts, aryCustomInds,
                                                            structPosition, structForward, structUp, structTexStart, structTexDimension, structW, structH, structD, BoundType.Box));
                                                    }
                                                }
                                                else
                                                {
                                                    holdSelected.Add(mainMap[currentSector].AddStructure(aryCustomVerts, aryCustomInds,
                                                        structPosition, structForward, structUp, structTexStart, structTexDimension, structW, structH, structD));

                                                    // if bound type selected
                                                    if (structBound == BoundType.Box)
                                                    { holdSelected.Add(mainMap[currentSector].AddBound(structPosition, structForward, structUp, structW, structH, structD)); }
                                                    else if (structBound == BoundType.Sphere)
                                                    { holdSelected.Add(mainMap[currentSector].AddBound(structPosition, (structW + structH + structD) / 3)); }
                                                }
                                                // Lock bounds if created with structure
                                                if (holdSelected.Count > 1)
                                                { AddSelected(mainMap[currentSector].PinObjects(holdSelected.ToArray())); }
                                                else
                                                { AddSelected(holdSelected[0]); }
                                                menuState = MenuState.Normal;
                                                break;
                                            case "Cancel":
                                                menuState = MenuState.Normal;
                                                break;
                                        }
                                    }
                                }
                                #endregion
                                break;
                            #endregion
                                
                            #region TRIGGER CREATE
                            case MenuState.TriggerCreate:
                                if (hudTrigger["CreateTrigger"].WndRect.Intersects(mouseRect))
                                {
                                    currentButtonName = hudTrigger["CreateTrigger"].Click(mouseRect);
                                    if (currentButtonName != null)
                                    {
                                        hudTrigger["CreateTrigger"].ModifyField(structTriggerType, Color.Gray);
                                        switch (currentButtonName)
                                        {
                                            case "Command":
                                                hudTrigger["CreateTrigger"].ModifyField("Command", Color.White);
                                                structTriggerType = "Command";
                                                break;
                                            case "Proximity":
                                                hudTrigger["CreateTrigger"].ModifyField("Proximity", Color.White);
                                                structTriggerType = "Proximity";
                                                break;
                                            case "Timed":
                                                hudTrigger["CreateTrigger"].ModifyField("Timed", Color.White);
                                                structTriggerType = "Timed";
                                                break;
                                            case "Ok":
                                                switch (structTriggerType)
                                                {
                                                    case "Command":
                                                        AddSelected(mainMap[currentSector].AddCommandTrigger(null, 0, 0));
                                                        break;
                                                    case "Proximity":
                                                        AddSelected(mainMap[currentSector].AddProximityTrigger(null, null, 0));
                                                        break;
                                                    case "Timed":
                                                        AddSelected(mainMap[currentSector].AddTimedTrigger(null, 5, 0));
                                                        break;
                                                }
                                                hudTrigger["CreateTrigger"].IsVisible = false;
                                                menuState = MenuState.Normal;
                                                break;
                                            case "Cancel":
                                                hudTrigger["CreateTrigger"].IsVisible = false;
                                                menuState = MenuState.Normal;
                                                break;
                                        }
                                    }
                                }
                                break;
                            #endregion
                                 
                        }
                    }
                    #endregion

                    #region RIGHT CLICK
                    if ((baseMouse.RightButton == XnaButtonState.Pressed) && (currentMouse.RightButton == XnaButtonState.Released))
                    {
                        Rectangle mouseRect = new Rectangle((int)(currentMouse.X), (int)(currentMouse.Y), 2, 2);

                        // Texture Set
                        if ((hudTexture["Main"].IsVisible) && (hudTexture["Main"]["ActiveTex"].DrawRect.Intersects(mouseRect)))
                        {
                            // Next X, with wrap
                            structTexStart.X -= structTexDimension.X;
                            if (structTexStart.X < 0)
                            {
                                structTexStart.X = 1 - structTexDimension.X;
                                // Next Y, with wrap
                                structTexStart.Y -= structTexDimension.Y;
                                if (structTexStart.Y < 0)
                                { structTexStart.Y = 1 - structTexDimension.Y; }
                            }
                        }
                    }
                    #endregion
                    break;
                case GameState.Simulating:
                    // Escape
                    if ((baseKey.IsKeyDown(Keys.Escape)) && (currentKey.IsKeyUp(Keys.Escape)))
                    { StopSimulation(); }

                    #region CAMERA MOVEMENT
                    // Mouse - (Turn, Look)
                    Vector2 dJoystick = JOYSTICK_SPEED * (new Vector2((float)(baseMouse.X - currentMouse.X) / (float)(safeArea.Width / 2), (float)(baseMouse.Y - currentMouse.Y) / (float)(safeArea.Height / 2)));
                    if (dJoystick.X != 0) { camera.Turn(dJoystick.X); }
                    if (dJoystick.Y != 0) { camera.LookVertical(dJoystick.Y); }
                    // Reset mouse
                    Mouse.SetPosition(safeArea.Width / 2, safeArea.Height / 2);
                    currentMouse = Mouse.GetState();

                    // W - Camera Forward
                    if (currentKey.IsKeyDown(Keys.W))
                    { camera.Stride(1); }

                    // S - Camera Backward
                    if (currentKey.IsKeyDown(Keys.S))
                    { camera.Stride(-1); }

                    // A - Camera Left
                    if (currentKey.IsKeyDown(Keys.A))
                    { camera.Strafe(1); }

                    // D - Camera Right
                    if (currentKey.IsKeyDown(Keys.D))
                    { camera.Strafe(-1); }

                    // Up - Camera Up
                    if (currentKey.IsKeyDown(Keys.Up))
                    { camera.LookVertical(1); }

                    // Down - Camera Down
                    if (currentKey.IsKeyDown(Keys.Down))
                    { camera.LookVertical(-1); }

                    // Left - Look Left
                    if (currentKey.IsKeyDown(Keys.Left))
                    { camera.Turn(1); }

                    // Right - Look Right
                    if (currentKey.IsKeyDown(Keys.Right))
                    { camera.Turn(-1); }

                    // Hold Shift - Run
                    if ((baseKey.IsKeyUp(Keys.LeftShift) && baseKey.IsKeyUp(Keys.RightShift))
                        && (currentKey.IsKeyDown(Keys.LeftShift) || currentKey.IsKeyDown(Keys.RightShift)))
                    { camera.MovementType = MoveType.Run; }
                    else if ((baseKey.IsKeyDown(Keys.LeftShift) || baseKey.IsKeyDown(Keys.RightShift))
                        && (currentKey.IsKeyUp(Keys.LeftShift) && currentKey.IsKeyUp(Keys.RightShift)))
                    { camera.MovementType = MoveType.Walk; }

                    // Hold Space - Slide
                    // Release Space - Jump
                    if ((baseKey.IsKeyUp(Keys.Space)) && (currentKey.IsKeyDown(Keys.Space)))
                    { camera.MovementType = MoveType.Slide; }
                    else if ((baseKey.IsKeyDown(Keys.Space)) && (currentKey.IsKeyUp(Keys.Space)))
                    { camera.RestoreMovementType(); camera.Jump(); }
                    #endregion
                    break;
            }

            // Finalize Input
            if (currentButtonName != null)
            {
                arySounds[SND_CLICK].Play();
                currentButtonName = null;
            }

            // Update Input
            baseKey = currentKey;
            baseMouse = currentMouse;
        }

        private void ProcessMessage(string displayText, MessageConfirm confirmCall)
        {
            hudMapManager["Message"].ModifyField("Text", displayText);
            hudMapManager["Message"].ModifyField("Text", Alignment.Center, Alignment.Center);
            hudMapManager["Message"].IsVisible = true;
            menuState = MenuState.Message;
            callbackConfirm = confirmCall;
        }

        private void RemoveSelected(params MapEntity[] aryRemove)
        {
            bool updateAnimation = false;
            bool updateTrigger = false;
            for (int i = 0; i < lstSelected.Count; i++)
            {
                bool remove = false;
                for (int a = 0; a < aryRemove.Length; a++)
                { if (aryRemove[a] == lstSelected[i]) { remove = true; } }

                if (remove)
                {
                    switch (lstSelected[i].Type)
                    {
                        case ObjectType.Animation:
                        case ObjectType.Frame:
                            updateAnimation = true;
                            break;
                        case ObjectType.Trigger:
                            updateTrigger = true;
                            break;
                    }
                    lstSelected.RemoveAt(i); i--;
                }
            }
            if (updateAnimation) { UpdateAnimationView(); }
            if (updateTrigger) { UpdateTriggerView(); }
        }

        private void RemoveSelected(params ObjectType[] aryRemoveTypes)
        {
            bool updateAnimation = false;
            bool updateTrigger = false;
            for (int i = 0; i < lstSelected.Count; i++)
            {
                bool remove = false;
                for (int a = 0; a < aryRemoveTypes.Length; a++)
                { if (aryRemoveTypes[a] == lstSelected[i].Type) { remove = true; } }

                if (remove)
                {
                    switch (lstSelected[i].Type)
                    {
                        case ObjectType.Animation:
                        case ObjectType.Frame:
                            updateAnimation = true;
                            break;
                        case ObjectType.Trigger:
                            updateTrigger = true;
                            break;
                    }
                    lstSelected.RemoveAt(i); i--;
                }
            }
            if (updateAnimation) { UpdateAnimationView(); }
            if (updateTrigger) { UpdateTriggerView(); }
        }

        private void SaveMap()
        {
            if (storageDevice.IsConnected)
            {
                string fileName = "Map_";
                int nameIndex = 0;
                IAsyncResult syncResult = storageDevice.BeginOpenContainer("Maps", null, null);
                
                // Wait for sync
                syncResult.AsyncWaitHandle.WaitOne();
                StorageContainer storageContainer = storageDevice.EndOpenContainer(syncResult);

                while (storageContainer.FileExists(fileName + nameIndex.ToString() + ".xml"))
                { nameIndex++; }

                // Save map
                MapData newSaveData = mainMap.SaveMap();              
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Indent = true;

                // Create file and save
                Stream fileStream = storageContainer.CreateFile(fileName + nameIndex.ToString() + ".xml");
                using (XmlWriter writer = XmlWriter.Create(fileStream, settings))
                { IntermediateSerializer.Serialize(writer, newSaveData, null); }

                // Close
                fileStream.Close();
                storageContainer.Dispose();
                // Complete
                arySounds[SND_DING].Play();
            }
        }

        private void SnapHuds(HUD lockedHud, string lockWindow, HUD adjustHud, string adjustWindow, SnapSide newSnap)
        {
            Rectangle snapRect, adjustRect;

            if (lockedHud[lockWindow].IsVisible)
            { snapRect = lockedHud[lockWindow].WndRect; }
            else
            { snapRect = lockedHud["System"].WndRect; }

            if (adjustHud[adjustWindow].IsVisible)
            { adjustRect = adjustHud[adjustWindow].WndRect; }
            else
            { adjustRect = adjustHud["System"].WndRect; }

            switch (newSnap)
            {
                case SnapSide.Top:
                    adjustRect.X = snapRect.X;
                    adjustRect.Y = snapRect.Y - adjustRect.Height;
                    break;
                case SnapSide.Bottom:
                    adjustRect.X = snapRect.X;
                    adjustRect.Y = snapRect.Y + snapRect.Height;
                    break;
                case SnapSide.Left:
                    adjustRect.X = snapRect.X - adjustRect.Width;
                    adjustRect.Y = snapRect.Y;
                    break;
                case SnapSide.Right:
                    adjustRect.X = snapRect.X + snapRect.Width;
                    adjustRect.Y = snapRect.Y;
                    break;
            }
            // Update hud
            adjustHud.Rect = adjustRect;
        }

        private void StartSimulation()
        {
            ClearSelected();
            camera.MovementType = MoveType.Walk;
            this.IsMouseVisible = false;
            Mouse.SetPosition(safeArea.Width / 2, safeArea.Height / 2);
            // Activate necessary objects
            for (int i = 0; i < mainMap.SectorCount; i++)
            {
                mainMap[i].ResetObject(mainMap[i].Interactives.ToArray());
                mainMap[i].ResetObject(mainMap[i].Triggers.ToArray());
                mainMap[i].ActivateObject(mainMap[i].Interactives.ToArray());
                mainMap[i].ActivateObject(mainMap[i].Triggers.ToArray());
            }
            gameState = GameState.Simulating;
            hudMapManager["Simulation"].ModifyField("Status", gameState.ToString());
        }

        private void StopSimulation()
        {
            camera.MovementType = MoveType.Float;
            this.IsMouseVisible = true;
            // Deactivate and reset necessary objects
            for (int i = 0; i < mainMap.SectorCount; i++)
            {
                mainMap[i].DeactivateObject(mainMap[i].Animations.ToArray());
                mainMap[i].DeactivateObject(mainMap[i].Interactives.ToArray());
                mainMap[i].DeactivateObject(mainMap[i].Triggers.ToArray());
                mainMap[i].ResetObject(mainMap[i].Animations.ToArray());
                mainMap[i].ResetObject(mainMap[i].Interactives.ToArray());
                mainMap[i].ResetObject(mainMap[i].Triggers.ToArray());
            }
            gameState = GameState.Normal;
            hudMapManager["Simulation"].ModifyField("Status", gameState.ToString());
        }

        private int TypeSelected(ObjectType reqType)
        {
            int isSelected = -1;
            for (int i = 0; i < lstSelected.Count; i++)
            {
                if (lstSelected[i].Type == reqType)
                { isSelected = i; break; }
            }
            return isSelected;
        }

        protected override void UnloadContent()
        {
            mainMenuManager.Unload();
            mainMap.Unload();
        }

        protected override void Update(GameTime gameTime)
        {
            float seconds = (float)gameTime.ElapsedGameTime.TotalSeconds;
            ProcessInput((int)seconds);

            // Update Map
            for (int i = 0; i < mainMap.SectorCount; i++)
            { mainMap.Update(seconds); }

            // Update Camera
            camera.Update(seconds);

            switch (gameState)
            {
                case GameState.Normal:
                    camera.CommitUpdate();

                    switch (menuState)
                    {
                        case MenuState.Create_Structure:
                            previewCamera.Update(seconds);
                            previewCamera.CommitUpdate();
                            break;
                    }

                    // Monitor selected items
                    Animation animHold = IsSelected(ObjectType.Animation) as Animation;
                    if (animHold != null)
                    { if (animHold.IsActive) { UpdateAnimationView(); } }
                    break;
                case GameState.Simulating:
                    // Collision
                    CollisionData[] aryPlayerData = mainMap.Collision(camera.Bound, camera.Velocity, camera.BaseFriction, true, null);
                    for (int pC = 0; pC < aryPlayerData.Length; pC++)
                    {
                        if (aryPlayerData[pC].Collision)
                        { camera.ChangeUpdate(aryPlayerData[pC]); }
                    }
                    camera.CommitUpdate();
                    break;
            }

            // Process Flags
            SectorFlag[] newFlags = mainMap[currentSector].TakeFlags();
            for (int i = 0; i < newFlags.Length; i++)
            {
                switch (newFlags[i])
                {
                    case SectorFlag.ModifiedVertices:
                        UpdateSectorView();
                        break;
                }
            }

            // Set new camera
            viewMat = camera.LookAt;
            // Update debug
            hudMapManager["Simulation"].ModifyField("GC", (GC.GetTotalMemory(false) / 1024).ToString());

            base.Update(gameTime);
        }

        private void UpdateAnimationView()
        {
            // **** Animation Select *****
            // Clear all non-main window fields
            List<Animation> lstAnimations = mainMap[currentSector].Animations;
            List<string> lstFieldNames = new List<string>(hudAnimation["AnimationSelect"].FieldNames);
            for (int i = 0; i < lstFieldNames.Count; i++)
            {
                if (lstFieldNames[i] != "Background")
                { hudAnimation["AnimationSelect"].RemoveField(lstFieldNames[i]); }
            }
            hudAnimation["AnimationSelect"].EnableLineTrack = true;
            // Refresh list
            MapEntity selectedAnimation = IsSelected(ObjectType.Animation);
            for (int i = 0; i < lstAnimations.Count; i++)
            {
                // Next line on evens
                if ((i != 0) && (i % 4 == 0))
                { hudAnimation["AnimationSelect"].NewLine(); }
                // Create selection box - highlight if selected
                if (selectedAnimation == lstAnimations[i])
                {
                    hudAnimation["AnimationSelect"].CreateCustomField(i.ToString(), aryEffects[EFFECT_BASIC], aryTextures[MENU_BLUE_GRAY], Color.White,
                        10, aryFonts[FONTS_SMALL], currentSector.ToString() + ":" + i.ToString(), Color.White, Alignment.None, Alignment.None, Alignment.Center, Alignment.Center, true);
                }
                else
                {
                    hudAnimation["AnimationSelect"].CreateCustomField(i.ToString(), aryEffects[EFFECT_BASIC], aryTextures[MENU_DARK_GRAY], Color.White,
                        10, aryFonts[FONTS_SMALL], currentSector.ToString() + ":" + i.ToString(), Color.White, Alignment.None, Alignment.None, Alignment.Center, Alignment.Center, true);
                }
            }

            // **** Animation View ****
            int frameDimensions = 0;

            // Clear all frames
            lstFieldNames = new List<string>(hudAnimation["FrameSelect"].FieldNames);
            for (int i = 0; i < lstFieldNames.Count; i++)
            {
                if ((lstFieldNames[i] != "Background") && (lstFieldNames[i] != "Ticker"))
                { hudAnimation["FrameSelect"].RemoveField(lstFieldNames[i]); }
            }

            // Clear all states
            lstFieldNames = new List<string>(hudAnimation["StateSelect"].FieldNames);
            for (int i = 0; i < lstFieldNames.Count; i++)
            {
                if (lstFieldNames[i] != "Background")
                { hudAnimation["StateSelect"].RemoveField(lstFieldNames[i]); }
            }

            MapEntity animTest = IsSelected(ObjectType.Animation);
            if (animTest != null)
            {
                Animation animHold = animTest as Animation;
                Rectangle frameRect = hudAnimation["FrameSelect"].WndRect;
                Rectangle stateRect = hudAnimation["StateSelect"].WndRect;
                // Create frame visuals
                for (int i = 0; i < animHold.Frames.Length; i++)
                {
                    frameDimensions = (int)(hudAnimation["FrameSelect"].WndRect.Height * .5f);
                    string frameID = "F" + i.ToString();
                    Vector2 newPosition = new Vector2(
                        frameRect.X - (int)(.5f * frameDimensions) + (int)(frameRect.Width * animHold.Frames[i].TimePosition / animHold.Duration),
                        frameRect.Y + (int)((frameRect.Height - frameDimensions) * .5f));
                    hudAnimation["FrameSelect"].CreateImageField(frameID, aryEffects[EFFECT_BASIC], aryTextures[MENU_ANIMATION_FRAME],
                        frameDimensions, frameDimensions, Color.Silver, Alignment.None, Alignment.None, true);
                    // Modify position
                    hudAnimation["FrameSelect"].ModifyField(frameID, newPosition);
                    // Highlight if selected
                    bool frameSelected = false;
                    MapEntity frameTest = animHold.Frames[i];
                    if (IsSelected(frameTest))
                    {
                        frameSelected = true;
                        hudAnimation["FrameSelect"].ModifyField(frameID, Color.White);
                    }

                    // ** Create frame state visuals
                    frameDimensions = (int)(hudAnimation["StateSelect"].WndRect.Height * .1f);
                    newPosition = new Vector2(stateRect.X - (int)(.5f * frameDimensions) + (int)(stateRect.Width * animHold.Frames[i].TimePosition / animHold.Duration), 0);
                    for (int a = 0; a < animHold.AnimatedObjects.Length; a++)
                    {
                        string structID = "S" + i.ToString() + ":" + a.ToString();
                        hudAnimation["StateSelect"].CreateImageField(structID, aryEffects[EFFECT_BASIC], aryTextures[MENU_ANIMATION_STRUCTURE],
                        frameDimensions, frameDimensions, Color.Silver, Alignment.None, Alignment.None, true);
                        // Modify position
                        newPosition.Y = stateRect.Y + (int)(a * 1.2f * frameDimensions);
                        hudAnimation["StateSelect"].ModifyField(structID, newPosition);
                        // Highlight if selected
                        if (frameSelected)
                        {
                            MapEntity stateTest = animHold.AnimatedObjects[a];
                            if (IsSelected(stateTest))
                            { hudAnimation["StateSelect"].ModifyField(structID, Color.White); }
                        }
                    }

                    // Update animation length
                    hudAnimation["TimeControl"].ModifyField("Length", animHold.Duration.ToString() + " s");
                    hudAnimation["TimeControl"].ModifyField("Length", Alignment.Center, Alignment.Max);
                }
                // Update ticker
                hudAnimation["FrameSelect"].ModifyField("Ticker", new Vector2(frameRect.X + (animHold.PlayPosition * frameRect.Width / animHold.Duration), hudAnimation["FrameSelect"]["Ticker"].DrawRect.Y));
            } // if animation
        }

        private void UpdateFileList()
        {
            // Clear menu
            List<string> lstFieldNames = new List<string>(hudMapManager["File"].FieldNames);

            // Clear all non-main window fields
            for (int i = 0; i < lstFieldNames.Count; i++)
            {
                if ((lstFieldNames[i] != "Background") && (lstFieldNames[i] != "Title") && (lstFieldNames[i] != "Ok") && (lstFieldNames[i] != "Cancel"))
                { hudMapManager["File"].RemoveField(lstFieldNames[i]); }
            }
            hudMapManager["File"].EnableLineTrack = true;

            // Get File Names
            if (storageDevice.IsConnected)
            {
                IAsyncResult syncResult = storageDevice.BeginOpenContainer("Maps", null, null);
                // Wait for sync
                syncResult.AsyncWaitHandle.WaitOne();
                StorageContainer storageContainer = storageDevice.EndOpenContainer(syncResult);

                string[] fileNames = storageContainer.GetFileNames();
                for (int i = 0; i < fileNames.Length; i++)
                {
                    hudMapManager["File"].CreateCustomField(fileNames[i], aryEffects[EFFECT_BASIC], aryTextures[MENU_DARK_GRAY],
                        (int)(.4f * hudMapManager["File"].WndRect.Width), (int)(.05f * hudMapManager["File"].WndRect.Height), Color.Silver,
                        aryFonts[FONTS_SMALL], fileNames[i], Color.WhiteSmoke, Alignment.None, Alignment.None, Alignment.Center, Alignment.Center, true);
                    if ((i + 1) % 2 == 0)
                    { hudMapManager["File"].NewLine(); }
                }
            }
        }

        private void UpdateMenuGraphics()
        {
            switch (menuState)
            {
                case MenuState.Normal:
                    // Update Active Texture
                    GraphicsDevice.SetRenderTarget(aryRenderTargets[RENDER_ACTIVE_TEX]);
                    GraphicsDevice.Clear(Color.Black);
                    // Set effect
                    aryEffects[EFFECT_TEX_HIGHLIGHT].CurrentTechnique = aryEffects[EFFECT_TEX_HIGHLIGHT].Techniques["Single"];
                    aryEffects[EFFECT_TEX_HIGHLIGHT].Parameters["texStart"].SetValue(structTexStart);
                    aryEffects[EFFECT_TEX_HIGHLIGHT].Parameters["texDimension"].SetValue(structTexDimension);
                    // Draw texture
                    spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.Default,
                                RasterizerState.CullCounterClockwise, aryEffects[EFFECT_TEX_HIGHLIGHT]);
                    spriteBatch.Draw(aryTextures[GetPaletteIndex(structPalette)], Vector2.Zero, Color.White);
                    // End - create texture - reset
                    spriteBatch.End();
                    GraphicsDevice.SetRenderTarget(null);
                    hudTexture["Main"].ModifyField("ActiveTex", (Texture2D)aryRenderTargets[RENDER_ACTIVE_TEX]);
                    hudTexture["Main"].ModifyField("TexPreview", aryTextures[GetPaletteIndex(structPalette)]);
                    aryEffects[EFFECT_TEX_HIGHLIGHT].CurrentTechnique = aryEffects[EFFECT_TEX_HIGHLIGHT].Techniques["Basic"];
                    break;
                case MenuState.Create_Structure:
                    // Update Preview
                    GraphicsDevice.SetRenderTarget(aryRenderTargets[RENDER_CREATE_STRUCTURE]);
                    GraphicsDevice.Clear(Color.Black);
                    // Set effect
                    aryEffects[EFFECT_SECTOR_BASIC].Parameters["view"].SetValue(previewCamera.LookAt);
                    aryEffects[EFFECT_SECTOR_BASIC].Parameters["projection"].SetValue(projMat);
                    aryEffects[EFFECT_SECTOR_BASIC].Parameters["world"].SetValue(Matrix.Identity);
                    aryEffects[EFFECT_SECTOR_BASIC].CurrentTechnique.Passes[0].Apply();
                    // Draw
                    GraphicsDevice.DrawUserIndexedPrimitives<CustomVD>(PrimitiveType.TriangleList,
                            aryCustomVerts, 0, aryCustomVerts.Length, aryCustomInds,
                            0, (int)(aryCustomInds.Length / 3));
                    // End - Update
                    GraphicsDevice.SetRenderTarget(null);
                    hudCreateStructure["Preview"].ModifyField("Background", (Texture2D)aryRenderTargets[RENDER_CREATE_STRUCTURE]);
                    break;
            }
        }

        private void UpdateObjectProperties()
        {
            Rectangle safeArea = GraphicsDevice.Viewport.TitleSafeArea;
            Rectangle iconRect = new Rectangle(0, 0, (int)(safeArea.Width * .02f), (int)(safeArea.Height * .03f));

            // Clear menu
            List<string> lstFieldNames = new List<string>(hudMapManager["ObjectInfo"].FieldNames);

            // Clear all non-main window fields
            for (int i = 0; i < lstFieldNames.Count; i++)
            {
                if ((lstFieldNames[i] != "Background") && (lstFieldNames[i] != "Title"))
                { hudMapManager["ObjectInfo"].RemoveField(lstFieldNames[i]); }
            }

            // Update - view last selected
            if (lstSelected.Count > 0)
            {
                MapEntity lastSelected = lstSelected[lstSelected.Count - 1];
                switch (lastSelected.Type)
                {
                    case ObjectType.Animation:
                        // ** PlayMode
                        hudMapManager["ObjectInfo"].CreateTextField("PlayMode", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL],
                            "PlayMode", Color.White, Alignment.Min, Alignment.Min, false);
                        // Forward
                        hudMapManager["ObjectInfo"].CreateCustomField("Forward", aryEffects[EFFECT_BASIC], aryTextures[MENU_DARK_GRAY],
                            iconRect.Width, iconRect.Height, Color.Silver, aryFonts[FONTS_SMALL], "Forward", Color.White,
                            Alignment.Center, Alignment.Min, Alignment.Center, Alignment.Center, true);
                        // Backward
                        hudMapManager["ObjectInfo"].CreateCustomField("Backward", aryEffects[EFFECT_BASIC], aryTextures[MENU_DARK_GRAY],
                            iconRect.Width, iconRect.Height, Color.Silver, aryFonts[FONTS_SMALL], "Backward", Color.White,
                            Alignment.Max, Alignment.Min, Alignment.Center, Alignment.Center, true);

                        if (((Animation)lastSelected).PlayMode == PlayMode.Forward)
                        { hudMapManager["ObjectInfo"].ModifyField("Forward", Color.White); }
                        else
                        { hudMapManager["ObjectInfo"].ModifyField("Backward", Color.White); }

                        // ** Repeat
                        hudMapManager["ObjectInfo"].CreateCustomField("Repeat", aryEffects[EFFECT_BASIC], aryTextures[MENU_DARK_GRAY],
                            iconRect.Width, iconRect.Height, Color.Silver, aryFonts[FONTS_SMALL], "Repeat", Color.White,
                            Alignment.Min, Alignment.Center, Alignment.Center, Alignment.Center, true);

                        if (((Animation)lastSelected).Repeat)
                        { hudMapManager["ObjectInfo"].ModifyField("Repeat", Color.White); }
                        break;
                    case ObjectType.Bound:
                        // ** Elasticity
                        hudMapManager["ObjectInfo"].CreateTextField("Elasticity", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL],
                            "Elasticity", Color.White, Alignment.OneThird, Alignment.Min, false);
                        // Lessen
                        hudMapManager["ObjectInfo"].CreateImageField("LessenE", aryEffects[EFFECT_BASIC], aryTextures[MENU_ARROW_LEFT],
                            iconRect.Width, iconRect.Height, Color.White, Alignment.Min, Alignment.Min, true);

                        // Current Amount
                        hudMapManager["ObjectInfo"].CreateTextField("CurrentEAmount", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL],
                            ((Bound)lastSelected).Elasticity.ToString(), Color.White, Alignment.TwoThirds, Alignment.Min, false);

                        // Increase
                        hudMapManager["ObjectInfo"].CreateImageField("IncreaseE", aryEffects[EFFECT_BASIC], aryTextures[MENU_ARROW_RIGHT],
                            iconRect.Width, iconRect.Height, Color.White, Alignment.Max, Alignment.Min, true);

                        // ** Friction
                        hudMapManager["ObjectInfo"].CreateTextField("Friction", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL],
                            "Friction", Color.White, Alignment.OneThird, Alignment.OneThird, false);
                        // Lessen
                        hudMapManager["ObjectInfo"].CreateImageField("LessenF", aryEffects[EFFECT_BASIC], aryTextures[MENU_ARROW_LEFT],
                            iconRect.Width, iconRect.Height, Color.White, Alignment.Min, Alignment.OneThird, true);

                        // Current Amount
                        hudMapManager["ObjectInfo"].CreateTextField("CurrentFAmount", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL],
                            ((Bound)lastSelected).Friction.ToString(), Color.White, Alignment.TwoThirds, Alignment.OneThird, false);

                        // Increase
                        hudMapManager["ObjectInfo"].CreateImageField("IncreaseF", aryEffects[EFFECT_BASIC], aryTextures[MENU_ARROW_RIGHT],
                            iconRect.Width, iconRect.Height, Color.White, Alignment.Max, Alignment.OneThird, true);

                        // ** Is Ladder
                        hudMapManager["ObjectInfo"].CreateTextField("IsLadder", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL],
                            "Is Ladder", Color.DarkGray, Alignment.Min, Alignment.Center, true);
                        if (((Bound)lastSelected).IsLadder)
                        { hudMapManager["ObjectInfo"].ModifyField("IsLadder", Color.White); }
                        break;
                    case ObjectType.Light:
                        break;
                    case ObjectType.Location:
                        break;
                    case ObjectType.Pinned:
                        break;
                    case ObjectType.Spawn:
                        // ** Spawn ID
                        hudMapManager["ObjectInfo"].CreateTextField("SpawnID", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL],
                            "Spawn ID", Color.White, Alignment.OneThird, Alignment.Min, false);
                        // Lessen ID
                        hudMapManager["ObjectInfo"].CreateImageField("LessenSpawn", aryEffects[EFFECT_BASIC], aryTextures[MENU_ARROW_LEFT],
                            iconRect.Width, iconRect.Height, Color.White, Alignment.Min, Alignment.Min, true);
                        // Current ID
                        hudMapManager["ObjectInfo"].CreateTextField("CurrentSpawn", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL],
                            ((Spawn)lastSelected).SpawnID.ToString(), Color.White, Alignment.TwoThirds, Alignment.Min, false);
                        // Increase ID
                        hudMapManager["ObjectInfo"].CreateImageField("IncreaseSpawn", aryEffects[EFFECT_BASIC], aryTextures[MENU_ARROW_RIGHT],
                            iconRect.Width, iconRect.Height, Color.White, Alignment.Max, Alignment.Min, true);

                        // ** Spawn Count
                        hudMapManager["ObjectInfo"].CreateTextField("SpawnCount", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL],
                            "Count", Color.White, Alignment.OneThird, Alignment.Center, false);
                        // Lessen Count
                        hudMapManager["ObjectInfo"].CreateImageField("LessenSpawnCount", aryEffects[EFFECT_BASIC], aryTextures[MENU_ARROW_LEFT],
                            iconRect.Width, iconRect.Height, Color.White, Alignment.Min, Alignment.Center, true);
                        // Current Count
                        hudMapManager["ObjectInfo"].CreateTextField("CurrentSpawnCount", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL],
                            ((Spawn)lastSelected).Count.ToString(), Color.White, Alignment.TwoThirds, Alignment.Center, false);
                        // Increase Count
                        hudMapManager["ObjectInfo"].CreateImageField("IncreaseSpawnCount", aryEffects[EFFECT_BASIC], aryTextures[MENU_ARROW_RIGHT],
                            iconRect.Width, iconRect.Height, Color.White, Alignment.Max, Alignment.Center, true);

                        // ** Spawn Delay
                        hudMapManager["ObjectInfo"].CreateTextField("SpawnDelay", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL],
                            "Delay", Color.White, Alignment.OneThird, Alignment.ThreeFourths, false);
                        // Lessen Delay
                        hudMapManager["ObjectInfo"].CreateImageField("LessenSpawnDelay", aryEffects[EFFECT_BASIC], aryTextures[MENU_ARROW_LEFT],
                            iconRect.Width, iconRect.Height, Color.White, Alignment.Min, Alignment.ThreeFourths, true);
                        // Current Delay
                        hudMapManager["ObjectInfo"].CreateTextField("CurrentSpawnDelay", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL],
                            ((Spawn)lastSelected).Delay.ToString(), Color.White, Alignment.TwoThirds, Alignment.ThreeFourths, false);
                        // Increase Delay
                        hudMapManager["ObjectInfo"].CreateImageField("IncreaseSpawnDelay", aryEffects[EFFECT_BASIC], aryTextures[MENU_ARROW_RIGHT],
                            iconRect.Width, iconRect.Height, Color.White, Alignment.Max, Alignment.ThreeFourths, true);
                        break;
                    case ObjectType.Structure:
                        if (lastSelected is InteractiveStructure)
                        {
                            // Object Title
                            hudMapManager["ObjectInfo"].CreateTextField("ObjectTitle", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL],
                            "Interactive Structure", Color.White, Alignment.Center, Alignment.Min, false);
                            // Bake state
                            hudMapManager["ObjectInfo"].CreateCustomField("BakeState", aryEffects[EFFECT_BASIC], aryTextures[MENU_LIGHT_GRAY],
                                Color.White, 5, aryFonts[FONTS_SMALL], "Bake State", Color.White, Alignment.Center,
                                Alignment.OneThird, Alignment.Center, Alignment.Center, true);
                        }
                        break;
                    case ObjectType.Trigger:
                        Trigger selectedTrigger = (Trigger)lastSelected;
                        // Title
                        string titleType = null;
                        if (selectedTrigger is CommandTrigger)
                        {
                            titleType = "Command Trigger";
                            // ** Command Title
                            hudMapManager["ObjectInfo"].CreateTextField("CommandTitle", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL],
                                "Command ID", Color.White, Alignment.OneThird, Alignment.TwoThirds, false);
                            // Lessen
                            hudMapManager["ObjectInfo"].CreateImageField("LessenCommand", aryEffects[EFFECT_BASIC], aryTextures[MENU_ARROW_LEFT],
                                iconRect.Width, iconRect.Height, Color.White, Alignment.Min, Alignment.TwoThirds, true);
                            // Current ID
                            hudMapManager["ObjectInfo"].CreateTextField("CurrentCommand", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL],
                                ((CommandTrigger)selectedTrigger).CommandIndex.ToString(), Color.White, Alignment.TwoThirds, Alignment.TwoThirds, false);
                            // Increase
                            hudMapManager["ObjectInfo"].CreateImageField("IncreaseCommand", aryEffects[EFFECT_BASIC], aryTextures[MENU_ARROW_RIGHT],
                                iconRect.Width, iconRect.Height, Color.White, Alignment.Max, Alignment.TwoThirds, true);
                        }
                        else if (selectedTrigger is ProximityTrigger)
                        {
                            titleType = "Proximity Trigger";
                            // ** Location Title
                            hudMapManager["ObjectInfo"].CreateTextField("LocationTitle", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL],
                                "Location", Color.White, Alignment.Min, Alignment.TwoThirds, false);
                            if (((ProximityTrigger)selectedTrigger).Location == null)
                            {
                                hudMapManager["ObjectInfo"].CreateTextField("NoLocation", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL],
                                  "NoneSelected", Color.White, Alignment.Center, Alignment.TwoThirds, false);
                            }
                            else
                            {
                                hudMapManager["ObjectInfo"].CreateImageField("LocationFound", aryEffects[EFFECT_BASIC], aryTextures[MENU_ADD_LOCATION],
                                    iconRect.Width, iconRect.Height, Color.White, Alignment.Center, Alignment.TwoThirds, true);
                            }
                            // Commit Location
                            hudMapManager["ObjectInfo"].CreateCustomField("CommitLocation", aryEffects[EFFECT_BASIC], aryTextures[MENU_DARK_GRAY],
                                Color.White, 2, aryFonts[FONTS_SMALL], "Commit Location", Color.White, Alignment.Max, Alignment.TwoThirds, Alignment.Center, Alignment.Center, true);
                        }
                        else if (selectedTrigger is TimedTrigger)
                        {
                            titleType = "Timed Trigger";
                            // ** Delay Title
                            hudMapManager["ObjectInfo"].CreateTextField("DelayTitle", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL],
                                "Delay", Color.White, Alignment.OneThird, Alignment.TwoThirds, false);
                            // Lessen
                            hudMapManager["ObjectInfo"].CreateImageField("LessenDelay", aryEffects[EFFECT_BASIC], aryTextures[MENU_ARROW_LEFT],
                                iconRect.Width, iconRect.Height, Color.White, Alignment.Min, Alignment.TwoThirds, true);
                            // Current Delay
                            hudMapManager["ObjectInfo"].CreateTextField("CurrentDelay", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL],
                                ((TimedTrigger)selectedTrigger).Delay.ToString(), Color.White, Alignment.TwoThirds, Alignment.TwoThirds, false);
                            // Increase
                            hudMapManager["ObjectInfo"].CreateImageField("IncreaseDelay", aryEffects[EFFECT_BASIC], aryTextures[MENU_ARROW_RIGHT],
                                iconRect.Width, iconRect.Height, Color.White, Alignment.Max, Alignment.TwoThirds, true);
                        }
                        // Type Title
                        hudMapManager["ObjectInfo"].CreateTextField("TypeTitle", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL], titleType,
                            Color.White, Alignment.Center, Alignment.Below, false);

                        // ** Target Title
                        hudMapManager["ObjectInfo"].CreateTextField("TargetTitle", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL],
                            "Target", Color.White, Alignment.Min, Alignment.OneThird, false);
                        if (selectedTrigger.TargetObject == null)
                        {
                            hudMapManager["ObjectInfo"].CreateTextField("NoTarget", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL],
                                "None Selected", Color.White, Alignment.Center, Alignment.OneThird, true);
                        }
                        else
                        {
                            hudMapManager["ObjectInfo"].CreateImageField("TargetFound", aryEffects[EFFECT_BASIC], aryTextures[MENU_ADD_LOCATION],
                                iconRect.Width, iconRect.Height, Color.White, Alignment.Center, Alignment.OneThird, true);
                        }
                        // Commit Target
                        hudMapManager["ObjectInfo"].CreateCustomField("CommitTarget", aryEffects[EFFECT_BASIC], aryTextures[MENU_DARK_GRAY],
                            Color.White, 2, aryFonts[FONTS_SMALL], "Commit Target", Color.White, Alignment.Max, Alignment.OneThird, Alignment.Center, Alignment.Center, true);
                    
                        // ** Occurrences Title
                        hudMapManager["ObjectInfo"].CreateTextField("OccurrencesTitle", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL],
                            "Occurrences", Color.White, Alignment.OneThird, Alignment.Above, false);
                        // Lessen
                        hudMapManager["ObjectInfo"].CreateImageField("LessenOccurrences", aryEffects[EFFECT_BASIC], aryTextures[MENU_ARROW_LEFT],
                            iconRect.Width, iconRect.Height, Color.White, Alignment.Min, Alignment.Above, true);
                        // Current Occurrences
                        hudMapManager["ObjectInfo"].CreateTextField("CurrentOccurrences", aryEffects[EFFECT_BASIC], aryFonts[FONTS_SMALL],
                            selectedTrigger.Occurences.ToString(), Color.White, Alignment.TwoThirds, Alignment.Above, false);
                        // Increase
                        hudMapManager["ObjectInfo"].CreateImageField("IncreaseOccurrences", aryEffects[EFFECT_BASIC], aryTextures[MENU_ARROW_RIGHT],
                            iconRect.Width, iconRect.Height, Color.White, Alignment.Max, Alignment.Above, true);
                        break;
                }
            }
        }

        private void UpdateSectorView()
        {
            // Is Visible
            if (mainMap[currentSector].IsVisible)
            { hudMapManager["Sectors"].ModifyField("IsVisible", Color.White); }
            else
            { hudMapManager["Sectors"].ModifyField("IsVisible", Color.Gray); }

            // Vertices
            float newSize = (((float)CustomVD.VertexDeclaration.VertexStride * (float)mainMap[currentSector].Vertices.Count) / 1024000);
            newSize = (float)Math.Floor(newSize * 100 + .5f) / 100;
            hudMapManager["Sectors"].ModifyField("Vertices", newSize.ToString());
        }

        private void UpdateTriggerView()
        {
            // Clear all non-main window fields
            List<Trigger> lstTriggers = mainMap[currentSector].Triggers;
            List<string> lstFieldNames = new List<string>(hudTrigger["TriggerSelect"].FieldNames);
            for (int i = 0; i < lstFieldNames.Count; i++)
            {
                if (lstFieldNames[i] != "Background")
                { hudTrigger["TriggerSelect"].RemoveField(lstFieldNames[i]); }
            }
            hudTrigger["TriggerSelect"].EnableLineTrack = true;

            // Refresh list
            int frameDimensions = (int)(hudTrigger["TriggerSelect"].WndRect.Height * .2f);
            MapEntity selectedTrigger = IsSelected(ObjectType.Trigger);
            for (int i = 0; i < lstTriggers.Count; i++)
            {
                Texture2D newTexture = null;
                Color newColor = Color.Gray;
                // Next line on evens
                if ((i != 0) && (i % 8 == 0))
                { hudTrigger["TriggerSelect"].NewLine(); }
                // Create selection box - highlight if selected
                if (selectedTrigger == lstTriggers[i])
                { newColor = Color.White; }
                // Get appropriate texture
                if (lstTriggers[i] is CommandTrigger)
                { newTexture = aryTextures[MENU_COMMAND]; }
                else if (lstTriggers[i] is ProximityTrigger)
                { newTexture = aryTextures[MENU_PROXIMITY]; }
                else if (lstTriggers[i] is TimedTrigger)
                { newTexture = aryTextures[MENU_CONTINUOUS]; }
                // Add Button
                hudTrigger["TriggerSelect"].CreateCustomField(i.ToString(), aryEffects[EFFECT_BASIC], newTexture, frameDimensions, frameDimensions, newColor, 
                    aryFonts[FONTS_SMALL], "T" + i.ToString(), Color.White, Alignment.None, Alignment.None, Alignment.Center, Alignment.Center, true);
                
            }
        }
    }
}
